nginx 리버스 프록시 URL을 업스트림의 IP 주소로 교체

nginx 리버스 프록시 URL을 업스트림의 IP 주소로 교체

나는 nginx를 사용하고 있습니다1.14.2다음 구성을 사용하여 역방향 프록시로

server {
        listen xxxxxxx:80;
        server_name xxxxxx;
        proxy_intercept_errors on;

        location /nodejs {
                proxy_pass https://nodejs.org;
                proxy_cache cache;
                proxy_cache_valid 200 301 302 30d;
                proxy_cache_valid 404 1m;
                expires 30d;
                proxy_ssl_server_name on;
                proxy_cache_use_stale error timeout invalid_header updating;
        }
}

나는 점점502 잘못된 게이트웨이브라우저에서:여기에 이미지 설명을 입력하세요 nginx 오류 로그에서 다음 줄을 발견했습니다.

2020/12/10 11:23:23 [error] 16462#16462: *1 connect() failed (110: Connection timed out) while connecting to upstream, client: xxxxxxx, server: xxxxxxxx, request: "GET /nodejs HTTP/1.1", upstream: "https://104.20.23.46:443/nodejs", host: "xxxxxxxx"

하지만 백엔드에 프록시가 있기 때문에 IP 주소가 포함된 URL은 차단됩니다. nginx가 업스트림에서 IP 주소 대신 도메인 이름을 사용하도록 강제하는 방법에 대해 알고 있습니까?

감사해요.

편집: Proxy_pass 구성에 다음 줄을 추가했습니다.

rewrite /nodejs/(.*) /dist  break;

이제 오류 로그는 다음과 같습니다.

2020/12/10 12:22:37 [error] 16541#16541: *1 connect() failed (110: Connection timed out) while connecting to upstream, client: xxxxxxx, server: xxxxxxxx, request: "GET /nodejs HTTP/1.1", upstream: "https://104.20.22.46:443/dist", host: "xxxxxxx"

답변1

다음 지시문이 필요합니다. proxy_ssl_server_name on;
기본값은 off입니다.

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ssl_server_name

관련 정보