Server/WebServer
response custom error page from proxy server
Jacob_baek
2022. 3. 3. 18:19
일반적으로 사용자의 요청에 대한 error 가 발생되면 origin 서버에서 error page를 rendering 하여 응답하게 된다.
만약 proxy 환경이라면 이를 proxy 서버에서 처리할수 있게 설정이 가능하다.
location ~ \.(7z|avi|avif|apkbin|bmp|bz2|png|...|jpg)$ {
...
proxy_pass http://192.168.1.1;
proxy_intercept_errors on;
error_page 404 500 501 502 503 /error_page.html;
...
}
location = /error_page.html {
root /tmp; ## <== /tmp/error_page.html 파일을 error page로 사용한다는 가정하에
internal;
}
테스트 용도이기에 error_page.html는 다음과 같이 간단하게 작성했다.
bash-5.1$ cat /tmp/error_page.html
<html>
error by jacobbaek
</html>
이후 요청을 보내면 다음과 같이 앞서 추가했던 html page를 응답하게 된다.
jacob@localhost:~/workspace$ curl -sk -X GET -D- https://proxy-test.jacobbaek.com/test_img.png
HTTP/2 404
date: Thu, 03 Mar 2022 05:22:09 GMT
content-type: text/html
content-length: 31
etag: "62204472-1f"
<html>
error by jacobbaek
</html>
비교를 위해 기존 error page는 nginx 기본 에러 페이지였다.
jacob@localhost:~/workspace$ curl -sk -X GET -D- https://proxy-test.jacobbaek.com/test_img.png
HTTP/2 404
date: Thu, 03 Mar 2022 05:09:05 GMT
content-type: text/html
content-length: 146
etag: "62204472-1f"
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
참고로 internal 지시자는 사용자가 직접 호출할때는 response를 제공하지 않고
내부적으로 요청이 전달될 경우 처리될수 있도록 하는 지시자이다.