So, I have nginx doing reverse proxying on the rails server. The rails server has an oauth login, and the lib that does this builds the callback URL using the "X-Forwarded-Host". The problem is that when nginx listens on a port other than 80, the return URL is not formatted properly. Looking at the configuration, I realized that this is due to the fact that it creates the URL with the "X-Forwarded-Host", and the configuration that I used did not include the port in it. To do this, I changed my configuration as follows:
server { listen 8081; server_name app; location / { proxy_pass http://app; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Host $host:8081; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; } }
My question is: what is X-Forwarded-Host? Nginx treats "Http-Host" as a host port, but I found on the network that sometimes the X-Forwarded-Host is only treated as a host, and it looks like the variable is called "X-Forwarded-Port", which is sometimes used, but I could not find anything in nginx docs, except that there is a variable available for printing in logs called "proxy port", but it is a port that is redirected and not the port accepted the connection (which is nothing to me because I use unix socket). What is the right solution? Nginx does not allow me the X-Forwarded-Port header manually, and I'm not even sure what it should. Looking back at the network, it seems that other http servers view this differently, for example:
Some related links:
Erich source share