후행 슬래시 없이 nginx 프록시 경로 https 리디렉션이 실패합니다.

후행 슬래시 없이 nginx 프록시 경로 https 리디렉션이 실패합니다.

Proxy_pass를 사용하여 여러 백엔드 서비스에 요청을 전달하도록 Nginx를 설정하려고 합니다.

후행 슬래시가 없는 페이지의 링크는 https://앞에 있지만 후행 슬래시가 있는 http 요청으로 리디렉션됩니다. 이는 연결 거부로 끝납니다. 이러한 서비스는 https를 통해서만 사용할 수 있기를 바랍니다.

따라서 링크가 너무https://example.com/internal/errorlogs

로드되면 브라우저에서 https://example.com/internal/errorlogs제공됩니다 Error Code 10061: Connection refused(로 리디렉션됨 http://example.com/internal/errorlogs/).

시험용 슬래시를 수동으로 추가하면 https://example.com/internal/errorlogs/로드됩니다.

나는 Proxypath와 Proxy.conf의 위치에 다양한 후행 슬래시를 추가하여 아무 효과도 없이 시도했지만 추가했습니다.server_name_in_redirect off;

이는 nginx 아래 두 개 이상의 앱에서 발생하며 Apache 역방향 프록시에서 작동합니다.

구성 파일

프록시.conf

location /internal {
    proxy_pass        http://localhost:8081/internal;
    include proxy.inc;
}
.... more entries ....

사이트 활성화/기본

server {
    listen 443;

    server_name example.com;
    server_name_in_redirect off;

    include proxy.conf;

    ssl on;
}

프록시.inc

proxy_connect_timeout   59s;
proxy_send_timeout      600;
proxy_read_timeout      600;
proxy_buffer_size       64k;
proxy_buffers           16 32k;
proxy_pass_header       Set-Cookie;
proxy_redirect          off;
proxy_hide_header       Vary;

proxy_busy_buffers_size         64k;
proxy_temp_file_write_size      64k;

proxy_set_header        Accept-Encoding         '';
proxy_ignore_headers    Cache-Control           Expires;
proxy_set_header        Referer                 $http_referer;
proxy_set_header        Host                    $host;
proxy_set_header        Cookie                  $http_cookie;
proxy_set_header        X-Real-IP               $remote_addr;
proxy_set_header        X-Forwarded-Host        $host;
proxy_set_header        X-Forwarded-Server      $host;
proxy_set_header        X-Forwarded-For         $proxy_add_x_forwarded_for;
proxy_set_header        X-Forwarded-Ssl         on;
proxy_set_header        X-Forwarded-Proto       https;

컬 출력

-$ curl -I -k https://example.com/internal/errorlogs/
HTTP/1.1 200 OK
Server: nginx/1.0.5
Date: Thu, 24 Nov 2011 23:32:07 GMT
Content-Type: text/html;charset=utf-8
Connection: keep-alive
Content-Length: 14327

-$ curl -I -k https://example.com/internal/errorlogs
HTTP/1.1 301 Moved Permanently
Server: nginx/1.0.5
Date: Thu, 24 Nov 2011 23:32:11 GMT
Content-Type: text/html;charset=utf-8
Connection: keep-alive
Content-Length: 127
Location: http://example.com/internal/errorlogs/

답변1

지시어 를 추가한 것을 보았는데 위치 세션에 지시어가 server_name_in_redirect필요합니다.proxy_redirect

http://wiki.nginx.org/HttpProxyModule#proxy_redirect

그런거 추가해줄게

proxy_redirect http://example.com/ /;

관련 정보