digitalocean / nginxconfig.io

⚙️ NGINX config generator on steroids 💉
https://do.co/nginxconfig
MIT License
27.66k stars 2.04k forks source link

Pass original port in all proxied queries #479

Open rayrapetyan opened 2 months ago

rayrapetyan commented 2 months ago

Feature request

Feature description

Currently in a reverse proxy generated section proxied port looks as below:

proxy_set_header X-Forwarded-Port  $server_port;

$server_port is the port nginx is listening on, which is not always the same port UA connects to (e.g. when nginx is listening inside a docker container on port 80, but UA connects to localhost:8080). IMO we should pass here the original port UA connects to, e.g. for http://localhost:8080 X-Forwarded-Port should be 8080. For this, a solution from https://stackoverflow.com/a/63366106/1017293 can be used, e.g. we need to add:

map $http_host $orig_port {
    default $scheme;
    "~^[^\:]+:(?<p>\d+)$" $p;
}

into http section of the nginx.conf and then in the proxy.conf use:

proxy_set_header X-Forwarded-Port  $orig_port;

How the feature is useful

Most of OAuth providers and any other server-side redirect solutions will work as expected.