【问题标题】:Change the Server Signature in NginX在 NginX 中更改服务器签名
【发布时间】:2020-02-05 12:47:40
【问题描述】:

我想在 Nginx 的 HTTP 400 错误 HTML 错误页脚中隐藏服务器签名。实现Headers-more 模块后。请求 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”页脚的错误页面。

【问题讨论】:

  • 您尝试过error_page 指令吗?不幸的是,“nginx”字在默认错误页面中是硬编码的:github.com/nginx/nginx/blob/…
  • 是的,我用过它,但它没有用。我要更改的错误是 400。

标签: nginx http-headers


【解决方案1】:

这是一个简单的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>

【讨论】:

  • 酷,去试试,然后给个反馈。
  • 它不起作用,同样的默认错误页面不断出现
猜你喜欢
  • 2014-08-27
  • 1970-01-01
  • 2019-04-19
  • 2015-06-09
  • 2014-04-30
  • 2020-09-28
  • 2019-11-04
  • 2016-05-03
  • 1970-01-01
相关资源
最近更新 更多