>  기사  >  백엔드 개발  >  Nginx 역방향 프록시 포트 도메인 이름에 액세스할 수 없는 문제가 해결되었습니다.

Nginx 역방향 프록시 포트 도메인 이름에 액세스할 수 없는 문제가 해결되었습니다.

WBOY
WBOY원래의
2016-08-08 09:29:203800검색

솔직히 새해 첫날 아침에 이 문제를 해결했습니다. 웹 프로젝트를 프록시하기 위해 도메인 이름을 사용하는 경우 요청 시 어떤 이유로 도메인 이름이 사용되지 않지만 IP 포트가 직접 경로로 사용되어 웹 페이지가 충돌하여 사용할 수 없게 됩니다.

프론트엔드 서버로 nginx를 사용하기 때문에 일부 수정을 가하여 수정 전과 후를 비교해 보겠습니다.

수정 전 :

서버 {
                                                                                            
proxy_pass http://10.14
8.2
2
.81 :8180;                           Proxy_set_header   X-Real-IP   $remote_addr; 인덱스 index.html } error_page 500 502 50 3 504 /50x. html; local = /50x.html {
루트 html;
} > }




수정됨:

서버 {

🎜> 위치 / {                 Proxy_pass http://10.14

8.2

2.8
1
:8180;                Proxy_set_header  X - 레알 -IP $remote_addr;
Proxy_set_header 호스트 $host:$server_port;
Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
index index.html index.htm; }       error_page 500 502 503 504 /50x.html; location = /50x.html { html; } }
}




접속 성공.



물론 정적 리소스의 경우

location ~ .*.(gif|jpg|png|html|htm| css|js|flv |ico|swf)(.*) {

Proxy_redirect off; Proxy_set_header 호스트 $host; Proxy_cache 캐시_one;

Proxy_cache_valid 200 302 1시간;

Proxy_cache_valid 301 1d ; proxy_cache_valid 임의 1분; 만료 30일;

index index.html index.htm;

}효율성이 더 좋습니다.



주요 참고자료는 원문입니다. 지도해주신 이 형님에게 매우 감사드립니다.


http://www.cnblogs.com /likehua/p/4056625.html

내용은 다음과 같습니다.

Nginx의 기본 역방향 포트가 80이므로 프록시입니다. 마지막 포트는 80이므로 접속 오류가 발생합니다. 주된 이유는 Nginx 구성 파일의 호스트 구성에 응답 포트가 설정되어 있지 않기 때문입니다.

관련 구성 파일은 다음과 같습니다.

1

2

3

4

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

위와 같이 Host 구성에는 호스트, 해당 포트가 없어 프록시되는 장소에서 잘못된 포트를 얻는 결과가 발생합니다. 이 문서에서는 Java를 예로 들어 설명합니다.

1

2

3

4

5

String scheme = httpRequest.getScheme();

    String serverName = httpRequest.getServerName();

    int port = httpRequest.getServerPort();

    //服务请求地址

    String requestURI = scheme+"://"+serverName+":"+port+"/ime-server/rest/"+serviceName+"/wmts";

1234 5문자열 구성표 = httpRequest.getScheme(); 문자열 serverName = httpRequest.getServerName(); 문자열 requestURI = 계획+":// "+serverName+":"+port+"/ime-server/rest/"+serviceName+"/wmts" ;

이때 획득한 포트는 80인데 nginx가 청취하는 포트는 9090이다. 이 오류는 나를 매우 우울하게 만듭니다. 따라서 nginx 구성 파일을 수정하고 호스트를 $host:$server_port로 변경합니다. 구성 파일은 다음과 같습니다.

1

2

3

4

5

6

7

8

location /ime-server {

            #root   html;

            #index  index.html index.htm;

            proxy_pass http://ime-server/ime-server;

            proxy_set_header Host $host:$server_port;

            proxy_set_header X-Real-IP $remote_addr;

            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }

1 2

3

4

5678 위치 /ime-server { 코드>#root html; #index index.html index.htm;proxy_pass; http: proxy_set_header 호스트 $host:$server_port;proxy_set_header; X-Real-IP $remote_addr;            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;           }
 nginx를 다시 시작합니다./nginx -s reload. 그런 다음 프록시 포트 정보가 올바른지 확인하세요. 위 내용은 관련 측면을 포함하여 Nginx 역방향 프록시 포트 도메인 이름에 액세스할 수 없는 문제에 대한 해결책을 소개합니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.