2012-01-03 2 views
30

저는 Unicorn으로 호스트 된 Sinatra 응용 프로그램과 그 앞에 nginx가 있습니다. Sinatra 응용 프로그램 오류 (500 반환), 기본 "내부 서버 오류"대신 정적 페이지를 제공하고 싶습니다. 따라서이 권한 문제가 아니에요,nginx이 내 error_page를 제공하지 않습니다.

server { 
    listen 80 default; 
    server_name *.example.com; 
    root /home/deploy/www-frontend/current/public; 

    location/{ 
    proxy_pass_header Server; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Scheme $scheme; 
    proxy_connect_timeout 5; 
    proxy_read_timeout 240; 
    proxy_pass http://127.0.0.1:4701/; 
    } 

    error_page 500 502 503 504 /50x.html; 
} 

error_page 지시자가, 나는 WWW 데이터 (우분투)로 sudo'd 내가 파일을 cat 수 있습니다 확인했습니다 : 나는 다음의 nginx 구성을 가지고있다. 위의 설정 파일과 service nginx reload을 사용하면 오류가 발생한 페이지가 여전히 "내부 서버 오류"와 같습니다.

무엇입니까? 내 오류입니다.

답변

60

error_page은 nginx에서 생성 된 오류를 처리합니다. 기본적으로 nginx는 http 상태 코드와 상관없이 프록시 서버가 반환하는 값을 반환합니다. 당신이 찾고있는 무엇

는 nginx를 400 이상의 HTTP 상태 코드로 응답을 차단한다면 proxy_intercept_errors

이 지시어는 결정이다.

기본적으로 모든 응답은 프록시 서버에서 현재 상태로 전송됩니다.

이 값을 on으로 설정하면 nginx는 error_page 지시문에 의해 명시 적으로 처리되는 상태 코드를 인터셉트합니다. error_page 지시문과 일치하지 않는 코드 코드를 가진 응답은 그대로 프록시 서버에서 으로 전송됩니다.

+1

나는 이것이 RTFM의 문제라는 것을 알고있었습니다. 시간을내어 훌륭한 답변을 제공해 주셔서 감사합니다. –

+9

4 세 응답에 대한 간단한 메모 - 이제'proxy_intercept_errors'는 300 이상의 오류에 대해 작동합니다. – Tisho

12

당신은 그 위치

location /some/location { 
    proxy_pass_header Server; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Scheme $scheme; 
    proxy_connect_timeout 5; 
    proxy_read_timeout 240; 
    proxy_pass http://127.0.0.1:4701/; 
    proxy_intercept_errors on; # see http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors 

    error_page 400 500 404 ... other statuses ... =200 /your/path/for/custom/errors; 
} 

특히 proxy_intercept_errors을 설정할 수 있으며 작업 할 수 proxy_intercept_errors on;를 사용하여, 스티븐 in this response에서 언급 한 바와 같이 당신이

+5

'proxy_intercept_errors; '(인수 없음)를 사용하면 현재 nginx에서 더 이상 유효하지 않습니다. 대신에'proxy_intercept_errors on;'을 사용하십시오. – Marian

+0

안녕 마리아, 얻은 주셔서 감사합니다 – Alexey

+0

여기에 의미에 대한 빠른 질문 ...'proxy_intercept_errors'를'on'으로 설정하면 사용자 정의 페이지가 반환되고 'off'로 설정하면 nginx 페이지가 반환됩니다. 맞습니까? – speedplane

0

을 필요 대신 200 다른 상태를 설정할 수 있습니다. 상류의 필요성이 매개 변수를 FastCGI를를 사용하는 uwsgi_intercept_errors on;가 속임수를 썼는지 사용 in this answer을 볼 때 내 경우에는 비록을 ...

0

사람들은, 내가 사용하고 내 PHP 응용 프로그램에 대한

fastcgi_intercept_errors on; 

켜져 내 업스트림 구성 블록에 있음

location ~ .php$ { ## Execute PHP scripts 
    fastcgi_pass php-upstream; 
    fastcgi_intercept_errors on; 
    error_page 500 /500.html; 
} 
관련 문제