How to redirect the value of the HTTP port during proxying?

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:

+7
source share
2 answers

My question is, what is actually defined as an "X-Forwarded-Host"?

It is not defined, therefore things are so controversial. I saw the port specified separately and as part of the host. For what it's worth, specifying it with the host seems to be common.

0
source

The application server has nginx on port 8081 and rails on 80.

Displays all requests to http://app:80 and changes the response header "Location" from http://app:80 to http://app:8081 .

 server { listen 8081; server_name app; location / { proxy_pass http://app:80; proxy_redirect http://app/ http://app:8081/; proxy_redirect http://app:80/ http://app:8081/; } } 
-3
source

All Articles