2016-07-22 7 views
0

현재 NGINX의 구성 문제로 인해 서버가 다운되었거나 디렉토리가 존재하지 않으면 NGINX 대신 502 오류가 계속 발생합니다.Nginx fallback with Node.js

포트 : 3000에서 Node.js 응용 프로그램을 실행하고 SSL을 설정하고 모든 HTTP 요청을 HTTPS로 리디렉션합니다. 내 node.js 응용 프로그램이 오프라인 인 시나리오에서 가능한 경우 클라이언트를 기본 NGINX 루트 디렉토리 /usr/share/nginx/htmlindex index.htm index.html으로 보내려고합니다.

포트 3000에서 nodejs 응용 프로그램을 /에 표시하려고하지만 서버가 다운 된 경우 NGINX 기본 디렉토리에서 폴백하여 대신 index.html을 표시하십시오. 누구든지이 과정을 통해 나를 도울 수 있습니까?

당신에게

편집 감사합니다 나는 jfriend00이 코멘트에서 밝혔다 시도했지만, 지금 내 proxy_pass은 작동하지 않습니다. 현재 내 서버가 실행 중인지 여부에 관계없이 기본값은 500.html입니다. 내 nginx.conf 파일을 첨부했습니다, 어떤 도움을 주시면 감사하겠습니다.

events { 
    worker_connections 1024; 
} 

http { 

    upstream nodejs { 
      server <<INTERNAL-PRIVATE-IP>>:3000; #3000 is the default port 
    } 

    ... 

    server { 
     listen 80; 
     server_name <<PUBLIC-IP>>; 
     return 301 $scheme://<<DOMAIN>>$request_uri; 
    } 

    server { 
     listen 443; 
     ssl on; 
       server_name <<DOMAIN>>.com www.<<DOMAIN>>.com; 

       ... 

       location/{ 
        proxy_pass http://nodejs; 
        proxy_redirect off; 
        proxy_set_header Host $host ; 
        proxy_set_header X-Real-IP $remote_addr ; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; 
        proxy_set_header X-Forwarded-Proto https; 
      } 

      error_page 501 502 503 /500.html; 

      location = /500.html { 
       root /usr/share/nginx/html; 
      } 

     } 
} 
+0

대답이없는 비슷한 질문이 있습니다. [http://stackoverflow.com/questions/15142692/varnish-nginx-node-js-static-nginx-html-pages-with-node-js-fallback](here) . 다른 구도자는 틀에 얽매이지 않는 방식으로 갔다. – Bryan

+0

여기 한 가지 방법 : http://serverfault.com/questions/511109/nginx-local-fallback-error-page-if-proxy-destination-is-unavailable – jfriend00

+0

흠. 나는 그것을 취할 것이지만, 한 눈에, 위치 블록 안에 루트를 두는 것은 나쁘지 않은가? @ jfriend00 – Bryan

답변

0

error_page를 추가하면 위에서 설명한대로 작동하고 성공적으로 다시 시작됩니다. @ jfriend00 감사합니다.

라이브 서버에 배포하는 경우 EC2에 배포 된 CentOS에서 proxy_pass 및 NGINX 구성이 작동하지 않는 이유를 파악하기가 어려워서 this을 확인하고 싶을 수 있습니다. 그것은 error_page와 아무 관련이 없습니다.