2013-10-14 10 views
1

노드 웹 앱 (api + web)을 제공하기 위해 nginx를 설정했지만 서버는 "/"(웹 루트) 호출에만 응답합니다. 테스트 할 때 주 웹 페이지 (/index.html에 있음)가 보이지만 이미지 또는 CSS 스타일이없고 경로/api/v1/.... (/ api/v1/users)에있는 api도 있습니다. ,/api/v1/cars 등)에 연결할 수 없습니다. nginx가 "찾을 수 없음"으로 응답하기 때문입니다.Nginx 및 node.js 경로 문제

현재의 nginx의 구성은 다음과 같습니다

server { 
    listen 80; 
    server_name localhost www.mydomain.com mydomain.com 

    access_log off; 
    error_log off; 

    location =/{ 
     proxy_pass http://127.0.0.1:3000; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header X-Real-IP $remote_addr; 
    } 
} 

가 어떻게 모든 경로를 제공하기 위해 nginx를 구성 할 수 있습니다?

답변

2

모든 경로를 일치 시키려면 = 기호를 누릅니다. = 접두어가 붙은 지시문은 쿼리와 정확히 일치합니다. 자세한 내용은 here을 참조하십시오.

location/{ 
    proxy_pass http://127.0.0.1:3000; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-Real-IP $remote_addr; 
} 

다음은 문서에서 샘플입니다 :

location =/{ 
    # matches the query/only. 
    [ configuration A ] 
} 
location/{ 
    # matches any query, since all queries begin with /, but regular 
    # expressions and any longer conventional blocks will be 
    # matched first. 
    [ configuration B ] 
} 
+0

죄송합니다! 당신 말이 맞아요. 대단히 감사합니다. – Endymion