Fixing a 403 Forbidden behind a Cloudflare Tunnel
nginx at the bottom, your tunnel, DNS and HTTPS are fine. The problem is inside the container: the folder is empty, the file is misnamed, or nginx can't read it. Check with ls -la from inside the container.
The setup
This site runs on my Asustor NAS as two Docker containers: nginx serves the files, and cloudflared holds an outbound tunnel open to Cloudflare. No ports are open on my router. I'd just finished creating the tunnel route and added a test index.html.
The symptom
Visiting the domain gave me this:
403 Forbidden
nginx
Step 1: Work out who sent the error
This is the most useful clue, and it's easy to skip. The page footer said nginx, not Cloudflare. That meant my request had already made it through Cloudflare's DNS, HTTPS and the tunnel, and reached my web server. So I could rule out half the setup straight away and stop poking at DNS records.
Step 2: Look from the container's point of view
What matters isn't what the folder looks like on the NAS, it's what nginx sees inside the container. In Portainer I opened a console on the nginx container and ran:
ls -la /usr/share/nginx/html
That one command points to one of three usual causes.
1. The folder is empty
If the path in the Docker volume mapping doesn't exactly match a real folder on the NAS (including capital letters), Docker quietly creates a new, empty one. nginx won't list a directory's contents by default, so an empty folder returns a 403 rather than a 404. Fix: correct the path in the stack and redeploy.
2. The file isn't really called index.html
Windows hides file extensions by default, so a file made in Notepad can actually be index.html.txt. Fix: turn on file name extensions in File Explorer and rename it.
3. nginx can't read the file
nginx's worker processes run as an unprivileged user, and NAS folder permissions can block it. Fix: give "others" read access to just that folder, without making anything writable:
chmod -R o+rX /volume1/Docker/website/html
What I took away from it
- Read the whole error page. The server name in the footer told me which layer to investigate.
- Check from inside the container. The host and the container can see very different things.
- Least privilege still applies when you're fixing things.
o+rXon one folder, and a read-only mount in Docker, beats reaching forchmod 777.