LoginSignup
65
62

More than 5 years have passed since last update.

nginxでリバースプロキシ時のエラーページを設定する

Posted at

nginxでproxy_passを使った時、通常はerror_page指定を無視してそのままのレスポンスを返す。

server {
  listen 80;
  server_name somewhere;

  error_page 404 /notfound.html; # 見に行かない

  location /app/ {
    proxy_pass http://internal/app/;
  }
}

これをカスタマイズするためには、proxy_intercept_errors on; を追加する。

参照:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors

server {
  listen 80;
  server_name somewhere;

  error_page 404 /notfound.html; # 404の場合参照される。
  error_page 403 =404 /notfound.html; # 403の場合404に変換される。

  location /app/ {
    proxy_pass http://internal/app/;
    proxy_intercept_errors on;
  }
}
65
62
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
65
62