Reputation: 9935
So, we need to conceal that nginx is our server and one of the ways in which it reveals itself is through its error pages. For that, we have a snippet:
error_page 404 /404.html;
error_page 403 /403.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /500.html;
# Non-rails error pages
error_page 301 /error/301.html;
error_page 307 /error/307.html;
error_page 308 /error/308.html;
error_page 400 /error/400.html;
error_page 401 /error/401.html;
error_page 405 /error/405.html;
error_page 406 /error/406.html;
error_page 408 /error/408.html;
error_page 413 /error/413.html;
error_page 415 /error/415.html;
error_page 429 /error/429.html;
error_page 431 /error/431.html;
location ^~ /error/ {
internal;
root /usr/share/nginx/html;
}
which is included into the server {}
block:
server {
listen 80;
server_name ourhost.com
include /etc/nginx/snippets/error_pages.conf;
return 301 https://$server_name$request_uri;
}
All pages contain just an error number and message without any revealing information. However, the 301 page still returns:
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
which isn't what we want. How do I make custom 301 page loaded instead of the default nginx one?
Upvotes: 2
Views: 2458
Reputation: 9935
The answer here helped: https://serverfault.com/questions/326877/nginx-error-page-directive-is-silently-ignored
Eclosing return
in location / {}
resolves the issue.
Upvotes: 2