NginxProxyManager / nginx-proxy-manager

Docker container for managing Nginx proxy hosts with a simple, powerful interface
https://nginxproxymanager.com
MIT License
23.31k stars 2.7k forks source link

proxy_set_header Host duplicates in the location #2076

Open Treverr opened 2 years ago

Treverr commented 2 years ago

I have a use case where I am proxying from my server to another hosted website. I found an issue where npm adds the proxy_set_header Host $host automatically, and I cannot override it manually, which I need to in this case because the $host is wrong and I needed to manually set it to the upstream host for CDN's to recognize it. $host is not defined so its null

I tried to do set $host in advanced but it just took my proxy offline.

For example, I need it to look like this:

  location / {
    proxy_set_header X-Forwarded-Scheme $scheme;
    proxy_set_header X-Forwarded-Proto  $scheme;
    proxy_set_header X-Forwarded-For    $remote_addr;
    proxy_set_header X-Real-IP      $remote_addr;
    proxy_pass       https://trever.mystrikingly.com:443;

    # Asset Caching
  include conf.d/include/assets.conf;

    # Force SSL
    include conf.d/include/force-ssl.conf;
    proxy_set_header Host "trever.mystrikingly.com";
  }

but NPM does not let that happen, it makes the configuration like this:

  location / {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Scheme $scheme;
    proxy_set_header X-Forwarded-Proto  $scheme;
    proxy_set_header X-Forwarded-For    $remote_addr;
    proxy_set_header X-Real-IP      $remote_addr;
    proxy_pass       https://trever.mystrikingly.com:443;

    # Asset Caching
  include conf.d/include/assets.conf;

    # Force SSL
    include conf.d/include/force-ssl.conf;
    proxy_set_header Host "trever.mystrikingly.com";
  }

Which does not work upstream.

pluigim commented 2 years ago

Hi have your same problem !

I have some host that don't work if you don't set proxy_set_header Host

with the called fqdn hostname.

Have you found any solution ?

Treverr commented 2 years ago

I had to manually go in and edit to remove that $host line that NPM adds only keeping my custom one.

Depending on your set up, You'll need to go into the docker itself 'docker exec -it nginsproxymanager sh' and and navigate to '/data/.../proxy_hosts' and edit the item manually.

pluigim commented 2 years ago

Hi !

What you suggested solved the problem !

Thanks

prashantsomashekar commented 2 years ago

@jc21 Is there no way to override this line, without resorting to this?

cromulus commented 2 years ago

same issue. Trying to proxy s3 through NPM and having this issue.

Thanks!

amjkwd commented 1 year ago

Hi, there, I had found a way to solve that. You can delete all your custom location in custom location tab, and add all location code in the advance tab. It works for me to add my 'proxy_set_header Host xxxxxxx', hope you too.

github-actions[bot] commented 9 months ago

Issue is now considered stale. If you want to keep it open, please comment :+1:

bilogic commented 7 months ago

For posterity due to the complete lack of documentation of NPM:

  1. In Details, use http, 0.0.0.0, 80 to show that settings on this page have no effect
  2. In Advanced, set
    location / {
        proxy_pass "https://source.com";
        proxy_set_header Host "source.com";
    }
github-actions[bot] commented 10 hours ago

Issue is now considered stale. If you want to keep it open, please comment :+1: