カスタム error_page は、PHP を使用しているときにのみ機能し、404 などのエラー ヘッダーを強制します。
しかし、NGINX に存在しない URL にアクセスしようとしたり、"return 404" を使用したりすると、カスタム ページではなく、常に既定の nginx ページが表示されます。
server {
listen 80;
listen [::]:80;
server_name www.test.com;
root /path/php;
error_page 403 /403.html;
error_page 404 /404.html;
error_page 429 /429.html;
error_page 500 /500.html;
error_page 501 /501.html;
error_page 502 /502.html;
error_page 503 /503.html;
error_page 504 /504.html;
location = /403.html {
root /another/path;
internal;
}
location = /404.html {
root /another/path;
internal;
}
location = /429.html {
root /another/path;
internal;
}
location = /500.html {
root /another/path;
internal;
}
location = /501.html {
root /another/path;
internal;
}
location = /502.html {
root /another/path;
internal;
}
location = /503.html {
root /another/path;
internal;
}
location = /504.html {
root /another/path;
internal;
}
location / {
rewrite ^(.+)$ /index.php?q=$1 last;
}
}