-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot proxy to sites that require a correct Host header #2675
Comments
If I understand correctly, currently NPM passes the hostname from the original request through to the upstream server. In many use-cases (perhaps the majority) this is probably the desired behaviour. Do you want the upstream server (S3 in your case) to see the value you entered in the UI for "Forward Hostname / IP"? |
I believe with reverese proxying, the target should not receive the original request's Host header. The target should receive a new Host header specific to the target (ie the s3 host example above) and it should additionally receive an X-Forwarded-For header indicating the original request's host header (actually XFF is a chain of forwarding headers beginning with the original request's Host header. |
You may just be right about that. I wonder if there is a public RFC which sets out the standard behaviour? You could create a pull request for the change and see if the maintainers will accept it. You'd also need to check the same change is applied to custom location declarations too. |
I met the same problem, I needed to use $proxy_host because I aim to speed up visiting a website. For example, I visit abc.com slowly, so I use my VPS and my domain abc.mydomain.com to proxy it. In this case, I should use $proxy_host instead of $host. Solution: Edit Advanced - Custom Nginx Configuration like below.
This is different from what I tested. The content in Advanced - Custom Nginx Configuration will replace config instead of appending I highly recommend that developers add an option in the web page graphical configuration, proxy_set_header Host is followed by $host or $proxy_host. Give the users a choice. |
I'm having the same problem. In my case the proxied app redirects to And you can indeed work around it by just pasting the custom nginx configuration, but thats kind of besides the point. The nginx default for Host is
IMHO the default should be respected, in the unlikely case that you truly want to overide Host with |
I deleted the line |
* $host is the Host sent by the user's browser. This is the correct setting if the service has built-in support for being proxied. * $proxy_host is the Host as if the browser would run on the proxy. This is the correct setting if the service does not have built-in support for reverse proxies. It is also the nginx default. * In nginx, you cannot unset the Host header. Configuring headers multiple times just sends multiple values with the http request. So there is no way to "fix" the Host by adding a custom header if it is already set. For these reasons, Host should not be set (and default to $proxy_host). In the unlikely case that your service needs something else you can then just set the header in the GUI. Fixes NginxProxyManager#2675
* $host is the Host sent by the user's browser. This is the correct setting if the service has built-in support for being proxied. * $proxy_host is the Host as if the browser would run on the proxy. This is the correct setting if the service does not have built-in support for reverse proxies. It is also the nginx default. * In nginx, you cannot unset the Host header. Configuring headers multiple times just sends multiple values with the http request. So there is no way to "fix" the Host by adding a custom header if it is already set. For these reasons, Host should not be set (and default to $proxy_host). In the unlikely case that your service needs something else you can then just set the header in the GUI. Fixes NginxProxyManager#2675
Issue is now considered stale. If you want to keep it open, please comment 👍 |
I conducted a test using the custom location feature and concluded that the header configuration within the custom location cannot override the default header configurations provided by nginxproxymanager, such as: perl |
Since this pr(#3729), I got the same problem, advanced_config should move to buttom? |
This line...
https://github.com/NginxProxyManager/nginx-proxy-manager/blame/develop/docker/rootfs/etc/nginx/conf.d/include/proxy.conf#L2
I believe should be...
proxy_set_header Host $proxy_host;
(I got the below to work by doing it)
Without that, proxy requests are being forwarded to websites with the original Host header and those sites are returning an error or a 404. For example, trying proxying data.example.com to an S3 bucket like mybucket.s3-website-us-east-1.amazonaws.com:80
S3 will reply with something like..
Further, you cannot override this proxy_set_header command by adding it to the advanced custom config in the UI because it simply appends the value to the existing header. ie, S3 will reply as blow (note the BucketName)...
Nor have I found a way to "unset" proxy_set_header Host. I tried using "Headers More" to no avail: https://www.nginx.com/resources/wiki/modules/headers_more/
The text was updated successfully, but these errors were encountered: