[GH-ISSUE #1460] Invalid proxy_pass with $upstream variable #1126

Closed
opened 2026-02-26 06:35:53 +03:00 by kerem · 4 comments
Owner

Originally created by @rmartcas on GitHub (Oct 5, 2021).
Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/1460

Checklist

  • Have you pulled and found the error with jc21/nginx-proxy-manager:latest docker image?
    • Yes
  • Are you sure you're not using someone else's docker image?
    • Yes
  • Have you searched for similar issues (both open and closed)?
    • Yes

Describe the bug
After proxy host config update, custom locations fails.
Checking the proxy host number.conf before and after the update i can see this difference:

Before:

location ^~ /jenkins/ {
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 http://127.0.0.01:8080/jenkins/;
}

After:

location ^~ /jenkins/ {
set $upstream http://127.0.0.01:8080/jenkins/;
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 $upstream;
}

The same ocurrs with all other custom locations in the proxy host.

Nginx Proxy Manager Version
v2.9.9

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

With the old proxy_pass http://.... works fine, but with variable set $upstream at begining of the location the proxy don't loads all related paths with custom locations

Screenshots

With new $upstream variable:
image

With old config or reventing the .conf manually and reloading nginx:
image

Operating System
Linux AMI

Additional context

Proxy host config files, before and after the last update.

proxy_conf_new.conf.txt
proxy_conf_old.conf.txt

Originally created by @rmartcas on GitHub (Oct 5, 2021). Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/1460 <!-- Are you in the right place? - If you are looking for support on how to get your upstream server forwarding, please consider asking the community on Reddit. - If you are writing code changes to contribute and need to ask about the internals of the software, Gitter is the best place to ask. - If you think you found a bug with NPM (not Nginx, or your upstream server or MySql) then you are in the *right place.* --> **Checklist** - Have you pulled and found the error with `jc21/nginx-proxy-manager:latest` docker image? - Yes - Are you sure you're not using someone else's docker image? - Yes - Have you searched for similar issues (both open and closed)? - Yes **Describe the bug** After proxy host config update, custom locations fails. Checking the proxy host number.conf before and after the update i can see this difference: Before: ``` location ^~ /jenkins/ { 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 http://127.0.0.01:8080/jenkins/; } ``` After: ``` location ^~ /jenkins/ { set $upstream http://127.0.0.01:8080/jenkins/; 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 $upstream; } ``` The same ocurrs with all other custom locations in the proxy host. **Nginx Proxy Manager Version** v2.9.9 **To Reproduce** Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error **Expected behavior** <!-- A clear and concise description of what you expected to happen. --> With the old proxy_pass http://.... works fine, but with variable set $upstream at begining of the location the proxy don't loads all related paths with custom locations **Screenshots** <!-- If applicable, add screenshots to help explain your problem. --> With new $upstream variable: ![image](https://user-images.githubusercontent.com/1176404/136047423-f8def03b-1653-422b-aa05-9bc90dff2085.png) With old config or reventing the .conf manually and reloading nginx: ![image](https://user-images.githubusercontent.com/1176404/136048090-04a38e25-aa61-43f8-9a56-2755422c6da4.png) **Operating System** Linux AMI **Additional context** <!-- Add any other context about the problem here, docker version, browser version, logs if applicable to the problem. Too much info is better than too little. --> Proxy host config files, before and after the last update. [proxy_conf_new.conf.txt](https://github.com/jc21/nginx-proxy-manager/files/7286820/proxy_conf_new.conf.txt) [proxy_conf_old.conf.txt](https://github.com/jc21/nginx-proxy-manager/files/7286821/proxy_conf_old.conf.txt)
kerem 2026-02-26 06:35:53 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@rmartcas commented on GitHub (Oct 5, 2021):

Some info from stackoverflow that could help.

https://stackoverflow.com/questions/46230270/nginx-using-variable-in-proxy-pass-breaks-routing

<!-- gh-comment-id:934521758 --> @rmartcas commented on GitHub (Oct 5, 2021): Some info from stackoverflow that could help. https://stackoverflow.com/questions/46230270/nginx-using-variable-in-proxy-pass-breaks-routing
Author
Owner

@chaptergy commented on GitHub (Oct 5, 2021):

Unfortunately I am not able to find a way which would allow both the usage of a variable for skipping domain caching and a working and generalizable path inclusion.
As the StackOverflow question also describes, proxy_pass expects a full url if it includes a variable, so no path is added to the host. This behaviour is also described in this article.
I have tried just adding the $request_uri variable to no avail, I've also tried using the regex location name which did not work and would not generalize well, and I've also tried a suggestion from a forum to use rewrite which did not work either.

Unless some fix is found which would fix both this issue and the one described in the commit, we would have to decide which issue is more relevant, either this one or the caching issue. I would personally say this issue is more relevant and to revert commit
github.com/jc21/nginx-proxy-manager@6c1ae77a2a. @jc21

Though the changes added in the commit could possibly also mitigate the issue raised in https://github.com/jc21/nginx-proxy-manager/issues/633.

<!-- gh-comment-id:934633407 --> @chaptergy commented on GitHub (Oct 5, 2021): Unfortunately I am not able to find a way which would allow both the usage of a variable for skipping domain caching and a working and generalizable path inclusion. As the StackOverflow question also describes, `proxy_pass` expects a _full_ url if it includes a variable, so no path is added to the host. This behaviour is also described in [this article](https://dev.to/danielkun/nginx-everything-about-proxypass-2ona#let-nginx-start-even-when-not-all-upstream-hosts-are-available). I have tried just adding the `$request_uri` variable to no avail, I've also tried using the regex location name which did not work and would not generalize well, and I've also tried a [suggestion from a forum](https://www.ruby-forum.com/t/proxy-pass-with-variable-removes-uri/239573/7) to use `rewrite` which did not work either. Unless some fix is found which would fix both this issue and the one described in the commit, we would have to decide which issue is more relevant, either this one or the caching issue. I would personally say this issue is more relevant and to revert commit https://github.com/jc21/nginx-proxy-manager/commit/6c1ae77a2a40283c5444c2f7e0a7c8227aeecbd2. @jc21 Though the changes added in the commit could possibly also mitigate the issue raised in https://github.com/jc21/nginx-proxy-manager/issues/633.
Author
Owner

@chaptergy commented on GitHub (Nov 14, 2021):

The changes have been reverted and should be included in the next release when it comes (2.9.13)

<!-- gh-comment-id:968275346 --> @chaptergy commented on GitHub (Nov 14, 2021): The changes have been reverted and should be included in the next release when it comes (2.9.13)
Author
Owner

@kabadisha commented on GitHub (Mar 19, 2023):

@shakamus & @chaptergy I took a look at this problem and think I have come up with a solution that works:
https://github.com/NginxProxyManager/nginx-proxy-manager/pull/2672
If you could take a look and test, that would be awesome :-)

<!-- gh-comment-id:1475247784 --> @kabadisha commented on GitHub (Mar 19, 2023): @shakamus & @chaptergy I took a look at this problem and think I have come up with a solution that works: https://github.com/NginxProxyManager/nginx-proxy-manager/pull/2672 If you could take a look and test, that would be awesome :-)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-proxy-manager-NginxProxyManager#1126
No description provided.