2016-07-02 1 views
0

웹 서버가 오프라인 상태 일 때 사용자 정의 502 오류 페이지를 표시하려하지만 작동하지 않습니다 : 기본 502 오류 페이지가 계속 표시됩니다. 업스트림이 오프라인 임).Nginx에서 사용자 정의 502 오류 페이지를 사용하지 않습니다

  • 정적 파일 /var/web/example.org/www/res에서 (예 : /var/web/example.org/www/res/robots.txt)은 다음과 같습니다

    내 파일 구성은 다음과 같다;

  • 오류 페이지가 /var/web/example.org/www (예 : /var/web/example.org/www/502.html) 미만입니다. 이것은 웹 서버가 켜져있을 때 오류 페이지 (404 및 기타를 포함하여 웹 서버 뒤에서 오는 것이 아니라)가 액세스 가능하기를 원하지 않기 때문입니다. 여기

내 (익명으로) 설정되어

error_page 502 /502.html; 
location /502.html { 
    root /var/web/example.org/www; 
    internal; 
} 
: 나는 또한 (마지막에 서버 블록)에 502을 잡기 위해 다음과 같은 정의 다음

upstream exampleorg { 
     server 127.0.0.1:8087; 
} 
server { 
    listen 80; 
    server_name www.example.org; 

    # content 
    # - static 
    root /var/web/example.org/www/res; 

    # - main webserver 
    error_page 403 404 @exampleorg; 
    error_page 502 /../502.html; 
    location @exampleorg { 
     proxy_pass http://exampleorg; 
     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 $scheme; 
    } 
} 

시도

하지만 nginx는 기본 502 페이지를 계속 표시합니다 (internal; 제외). 어떻게해야합니까? 솔루션에 미리 감사드립니다 :)

답변

1

몇 가지 실험을 한 후 해결책을 찾았습니다. 나는 error가 "error_page"404 문장으로부터 왔다고 생각한다. 그리고 나는 try_files이 그렇게 강력하다고 생각하지 않았다. 어쨌든, 그것이 어떤 사람들에게는 유용 할 수 있기 때문에 그것이 작동하는 마지막 구성입니다 :

upstream exampleorg { 
     server 127.0.0.1:8087; 
} 
server { 
    listen 80; 
    server_name www.example.org; 

    # content 
    # - static 
    location/{ 
     root /var/web/example.org/www/res; 
     try_files $uri @exampleorg; 
    } 

    # - main webserver 
    location @exampleorg { 
     proxy_pass http://exampleorg; 
     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 $scheme; 
    } 

    # - error 
    error_page 502 @offline; 
    location @offline { 
     root /var/web/example.org/www; 
     try_files /502.html 502; 
    } 
} 
관련 문제