Nginx에서 후행 슬래시가 누락되어 프록시 뒤의 잘못된 URL로 리디렉션됩니다.

Nginx에서 후행 슬래시가 누락되어 프록시 뒤의 잘못된 URL로 리디렉션됩니다.

우리는 nginx 프록시 뒤에 nginx 웹 서버를 사용합니다. 하위 경로를 탐색하려고 하면 nginx 백엔드 웹 서버(something.example.local)가 예상대로 URL(301 리디렉션) 뒤에 슬래시를 추가합니다. 내 문제는 프런트 엔드 프록시에 의해 게시되지 않고 마스크되도록 의도된 잘못된 URL로 리디렉션된다는 것입니다. 이 문제를 제거하는 가장 좋은 해결책은 무엇입니까?

(저는 다음과 같은 많은 제안을 시도했지만 아무 것도 효과가 없었습니다.

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/ 절대 리디렉션 꺼짐, 프록시 리디렉션 구성, 백엔드 서버의 규칙 다시 쓰기)

Nginx "프런트엔드" 프록시 구성:

        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

관련 정보