I am using nginx in a standard reverse proxy scenario, to pass all requests to /auth
to another host, however I'm trying to use non-standard ports.
My end goal is to have the X-Forwarded-Port
header set to the port that the request comes in on.
Here is my location block in nginx.conf:
location /auth/ { proxy_pass http://otherhost:8090; 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; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port <VAR>; }
This nginx is running in a docker container, that is configured to forward requests from 8085 into 80 in the container, such that the nginx process is listening on 80:
0.0.0.0:8085->80/tcp
When I hit the URL:
I am correctly redirected to http://otherhost:8090
, but the X-Forwarded-Port
header is missing or wrong.
Where I have <VAR>
in the original block, I have tried the following:
$server_port
- This is the port nginx is listening on (80), not the request port.$pass_port
- Seems to be null in my setup, so nginx drops the header.$http_port
- This is a random port per request.$remote_port
- This is a random port per request.
I can change my config at deploy time to hardcode to the known port of incoming requests, but ideally I would be able to change the front port without any change to the nginx config.
I've scoured the nginx variable list but can't find anything like $request_port
. Is there any way for me to achieve my intent?
$remote_port
? Apart from that, I have difficulties to understand how the port nginx is listening to ($server_port
) would be different from the request's port. – Anabantid