-1

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

5poharviz
  • 1
  • 1
  • Please re-read the guidance for the tags you've used. This is clearly a question about system configuration, not about __programming__, so is off-topic for Stack Overflow. It _might_ be suitable for [sf]: consult the Help Centre for the site before you post. – Toby Speight Aug 31 '23 at 14:28
  • The [proxy_redirect](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect) directive will modify the text of the `location:` header in a 3xx response. The default is looking for the **exact** text `https://something.example.local/wrongpath/` - if the upstream is returning something different, you will need to add one or more `proxy_redirect` statements. – Richard Smith Sep 01 '23 at 09:26

0 Answers0