2016-10-06 3 views
1

기본적으로 NGINX가 404를 반환하면 기본 HTML이 렌더링됩니다. 예를 들어, 다음과 같습니다.리디렉션없이 NGINX 맞춤 404 페이지

<html> 
<head><title>404 Not Found</title></head> 
<body bgcolor="white"> 
<center><h1>404 Not Found</h1></center> 
<hr><center>nginx/1.10.0 (Ubuntu)</center> 
</body> 
</html> 

이 HTML은 사용자 정의하고 URL은 변경하지 않고 그대로 사용하고 싶습니다. 나는 404에 대한 오류 페이지 설정을 시도했다 :

error_page 404 /404.html 

그러나이 첫 번째 /404.html에 브라우저를 리디렉션합니다.

리디렉션하지 않고 404 HTML을 사용자 정의 할 수있는 방법이 있습니까?

+2

'error_page 404 /404.html을, '경로 재를 생성 할 것이다. 전체 URL을 지정하여 강제로 리디렉션 할 수 있지만 질문에있는 양식에서 리디렉션을 생성해서는 안됩니다. 자세한 내용은 [이 문서] (http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page)를 참조하십시오. –

+0

아, 네 말이 맞아. 방금 다시 시도했는데 예상대로 작동합니다. 어떤 설정을했는지 확실하지 않아서'/ 404.html'로 리디렉션되었습니다. 감사! – scttnlsn

답변

1

는 Nginx에의 error_pageproxy_intercept_errors 지시어를 사용하여 당신이 다음과 같이 그것을 할 수있을 수 있습니다 nginx를 공식 사이트에

상세 설정

server { 
    ## other config 
    ## here the proxy_intercept_errors directive is the key 
    proxy_intercept_errors on; 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     ## your 50x.html file parent directory 
     root /var/www; 
    } 
    error_page 404 /404.html; 
    location = /404.html { 
     ## your 404.html file parent directory 
     root /var/www; 
    } 
} 

문서 :

proxy_intercept_errorserror_page