0

We use an nginx webserver behind an nginx proxy. When i try to browse a subpath, the nginx backend webserver (something.example.local) appends a trailing slash behind the url (301 redirect) -as expected-. My problem is, it redirects to the wrong url, which is not published by the frontend proxy and meant to be masked. What's the best solution to eliminate this problem?

(I tried many suggestions like these, but none of them worked:

https://serverfault.com/questions/1043091/unexpected-301-redirects-from-nginx-when-behind-nginx-reverse-proxy https://bluegrid.io/edu/how-to-add-a-trailing-slash-on-urls-in-nginx/ https://stackoverflow.com/questions/22759345/nginx-trailing-slash-in-proxy-pass-url https://www.shellhacks.com/nginx-proxy_pass-without-trailing-slash/ absolute redirect off, proxyredirect configs, rewrite rules on the backend server )

Nginx "frontend" proxy config:

        location /goodpath/ {
                proxy_pass       https://something.example.local/wrongpath/;
                proxy_set_header Host      example.com:$server_port;
                proxy_set_header X-Real-IP $remote_addr;
        }
# curl -I https://example.com/goodpath
HTTP/1.1 301 Moved Permanently
server: nginx
date: Thu, 31 Aug 2023 13:29:25 GMT
content-type: text/html
content-length: 162
location: **https://example.com/goodpath/**


$ curl -I **https://example.com/goodpath/subpath**
HTTP/1.1 301 Moved Permanently
server: nginx
date: Thu, 31 Aug 2023 13:30:23 GMT
content-type: text/html
content-length: 162
location: **https://example.com/*wrongpath*/subpath/**
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
strict-transport-security: max-age=31536000; includeSubDomains

1
  • proxy pass should never end with a slash on the end
    – djdomi
    Sep 5 at 17:12

0

You must log in to answer this question.

Browse other questions tagged .