Modify Nginx 301 response body
There's a great post about custom error pages at the following URL. The following is an abbreviated version of how it can be used to remove nginx branding from the 301
and 302
HTTP responses.
One NGINX error page to rule them all
nginx.conf
http {
map $status $status_text {
301 'Moved Permanently';
302 'Found';
}
server {
listen 1.1.1.1;
server_name _;
error_page 301 302 /error.html;
location = /error.html {
ssi on;
internal;
auth_basic off;
root /var/website/custom_error_pages;
}
root /var/website/empty_dir;
location / {
return 301 https://www.website.com$request_uri;
}
}
/error.html
<html>
<head><title>www.website.com</title></head>
<body><h1>
<!--# echo var="status" default="000" --> - <!--# echo var="status_text" default="Error" -->
</h1></body>
</html>
create file 301.html
, this file should contains content which you want to display. If path to file is /usr/share/nginx/html/301.html
adjust config to:
server {
listen 80;
server_name localhost;
location / {
error_page 301 = /301.html;
return 301 https://$host$request_uri;
}
location /301.html {
root /usr/share/nginx/html/;
}
}
And this will return your custom 301.html file