Skip to content

fix(nginx): custom locations take precedence over Cache Assets regex (location ^~)#5697

Open
pos-ei-don wants to merge 1 commit into
NginxProxyManager:developfrom
pos-ei-don:fix-custom-location-cache-precedence
Open

fix(nginx): custom locations take precedence over Cache Assets regex (location ^~)#5697
pos-ei-don wants to merge 1 commit into
NginxProxyManager:developfrom
pos-ei-don:fix-custom-location-cache-precedence

Conversation

@pos-ei-don

Copy link
Copy Markdown

Problem

A proxy host with a Custom Location pointing at a different upstream (e.g. /paperless -> a Paperless container) and Cache Assets enabled returns 404 for static files under that path (/paperless/static/app.js, .css, ...). The Custom Location's HTML/API paths work; only asset extensions break.

Root cause

Cache Assets includes a server-level regex location location ~* \.(css|js|png|...)$ { proxy_pass <main upstream>; }. In nginx, regex locations take precedence over prefix locations, so this regex beats the Custom Location location {{ path }} (plain prefix) generated by _location.conf. Asset requests under custom paths are routed to the main upstream (which doesn't know them) -> 404. The UI offers no way to raise the custom location's priority.

Related: #2557, #1981, #4423.

Change

Emit custom locations as location ^~ {{ path }}. ^~ gives the prefix location precedence over regex locations, so the cached-asset regex no longer hijacks custom-location paths.

Caveat

^~ disables regex matching within that path. Users who intend a Custom Location path as a regex would be affected. If custom paths may be regex, a guarded variant (only ^~ for plain prefixes) would be safer — happy to adjust based on maintainer preference.

Test

  1. Proxy host example -> upstream A; Custom Location /sub -> upstream B serving /sub/x.js.
  2. Enable Cache Assets -> /sub/x.js = 404 (bug).
  3. With this change -> /sub/x.js = 200 from B; main-upstream assets still cached.

Emit custom locations as `location ^~` so a configured Custom Location
(pointing at a different upstream) is not overridden by the server-level
`Cache Assets` regex location, which otherwise routes its static files
(.css/.js/...) to the main upstream -> 404.
@nginxproxymanagerci

Copy link
Copy Markdown

Docker Image for build 1 is available on DockerHub:

nginxproxymanager/nginx-proxy-manager-dev:pr-5697

Note

Ensure you backup your NPM instance before testing this image! Especially if there are database changes.
This is a different docker image namespace than the official image.

Warning

Changes and additions to DNS Providers require verification by at least 2 members of the community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant