yellowyolkblue

nginx reverse proxy notes I keep losing

I have written this same proxy block maybe forty times and I look it up every single time. So here it is, parked somewhere I'll actually find it.

location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

The line everyone forgets is X-Forwarded-Proto. Leave it out and your app thinks every request arrived over plain HTTP, then it cheerfully builds redirect loops back to https and you spend an hour blaming the browser.

For WebSockets, add the Upgrade and Connection headers and bump proxy_read_timeout, or your sockets die at sixty seconds on the dot. Ask me how I learned that one. Actually, don't.