2017-01-12 3 views
1

내 Nginx가 설치되어 실행 중입니다. 아래에있는 설정은 /etc/nginx/nginx.conf입니다. /api/*을 포트 9100 (유형 http://myhost:9100/api/apps)에서 동일한 서버에서 실행중인 My Tomcat 서버로 전달하고 싶습니다. '/ usr/share/nginx/html'아래 정적 파일을 제공하십시오. 이제 http://myhost/api/apps에 404를 입력합니다. 여기에 무슨 문제가 있습니까?Nginx 리버스 프록시 반환 404

upstream myserver { 
    server localhost:9100 weight=1; 
} 

server { 
    listen  80 default_server; 
    listen  [::]:80 default_server; 
    server_name _; 
    root   /usr/share/nginx/html; 

    # Load configuration files for the default server block. 
    include /etc/nginx/default.d/*.conf; 



    location ^~ /api/ { 
     proxy_pass http://myserver/; 
    } 

    location/{ 
    } 
} 

답변

2

proxy_pass 문 수도 선택적으로 상류를 전달하기 전에 URI를 수정합니다. 자세한 내용은 this document을 참조하십시오. 이 형태에서

:

URI를 /api/foohttp://myserver/foo에 전달
location ^~ /api/ { 
    proxy_pass http://myserver/; 
} 

. proxy_pass 문에서 후행 /을 삭제하여

은 :

location ^~ /api/ { 
    proxy_pass http://myserver; 
} 

URI입니다 /api/foo 지금 http://myserver/api/foo 전달됩니다.

+0

고마워요, 당신이 말한 것처럼 작동합니다. – July

관련 문제