nginx keep port number when 301 redirecting nginx keep port number when 301 redirecting nginx nginx

nginx keep port number when 301 redirecting


If nginx is not listening on port 8001, it cannot know which port to use in the redirect. You will need to specify it explicitly:

location ~ /foo(.*)$ {    return 301 $scheme://$http_host$1;}location ~ /adminfoo(.*)$ {    return 301 $scheme://$http_host/admin$1;}

The $http_host variable consists of the hostname and port from the original request. See this document for details.


For me, editing the following lines in proxy.conf to look like this, did the trick:

proxy_set_header Host $http_host;proxy_set_header X-Forwarded-Host $http_host;