如何更改NginX中的服务器签名

我想要在Nginx的HTTP 400错误HTML错误页页脚中隐藏服务器签名。在实现[Headers-more](https://github.com/openresty/headers-more-nginx-module)模块之后,当请求HTTP包时,服务器签名会更改:

>> curl -I localhost

输出:

HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Content-Length: 162
Connection: keep-alive
Location: https://www.abshnb.com/
Server: Abshnb

但HTTP 400错误HTML页面仍返回带有“nginx”页脚的错误页面。

点赞
用户9783845
用户9783845

下面是error_page指令的一个非常简单的例子,其中错误响应由nginx自己生成:

    server {
        listen 8888;
        server_tokens off;
        ...
        error_page 400 502 @error;

        location @error {
            default_type text/html;
            return 200 '<center><h1>$status</h1></center>';
        }

        location = /error400 {
            return 400;
        }

        location = /error502 {
            return 502;
        }

自定义错误处理程序:

$ http :8888/error400

HTTP/1.1 400 Bad Request
Connection: close
Content-Length: 29
Content-Type: text/html
Date: Sat, 08 Feb 2020 11:43:05 GMT
Server: nginx

<center><h1>400</h1></center>

默认错误处理程序:

$ http :8888/nonexistent

HTTP/1.1 404 Not Found
Connection: keep-alive
Content-Length: 162
Content-Type: text/html
Date: Sat, 08 Feb 2020 11:47:19 GMT
Server: nginx

<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
2020-02-08 11:59:34