修复方法分为两种: 1. 直接隐藏掉nginx的版本信息 2. 修改web服务器所使用的nginx的名称和版本信息 1.直接隐藏掉nginx的版本信息 shell
修复HTTP头信息泄露Nginx版本信息漏洞
发布时间: 2025-07-23 (a year ago)
LinuxNginx

- 修复方法分为两种:

复制代码
1. 直接隐藏掉nginx的版本信息
2. 修改web服务器所使用的nginx的名称和版本信息

1.直接隐藏掉nginx的版本信息

shell 复制代码
# 添加内容
[root@VM_0_12_centos conf]# vim nginx.conf
server_tokens off;
shell 复制代码
 浏览器控制台抓包可以看到:
 **Response Headers**
	Accept-Ranges: bytes
	Content-Length: 739
	Content-Type: text/html
	Date: Tue, 30 Jun 2020 07:53:36 GMT
	ETag: "5e9bc167-2e3"
	Last-Modified: Sun, 19 Apr 2020 03:11:35 GMT
	Server: nginx

2.修改web服务器所使用的nginx的名称和版本信息

shell 复制代码
(1)一共需要修改三个文件。包括:

    ·src/core目录下的nginx.h文件
    ·src/http目录下的ngx_http_header_filter_module.c文件
    ·src/http目录下的ngx_http_special_response.c文件

(2)修改内容如下:
 [root@VM_0_12_centos core]# vim nginx.h
 #define NGINX_VERSION      "" 
 #define NGINX_VER          "CSDN" NGINX_VERSION
 
 [root@VM_0_12_centos http]# vim ngx_http_header_filter_module.c
 static u_char ngx_http_server_string[] = "Server: CSDN" CRLF;
 
 [root@VM_0_12_centos http]# vim ngx_http_special_response.c
 static u_char ngx_http_error_tail[] =
 "<hr><center>CSDN</center>" CRLF
 "" CRLF
 "" CRLF

 (3) 重新编译nginx并启动
     [root@VM_0_12_centos nginx]# ./configure --prefix=/usr/local/nginx
 	 [root@VM_0_12_centos nginx]# make &amp;&amp; make install
 	 [root@VM_0_12_centos sbin]# kill -9 PID
 	 [root@VM_0_12_centos sbin]# ./nginx -c

/usr/local/nginx/conf/nginx.conf  #重新加载配置文件并启动

(4)浏览器控制台抓包可以看到:
  **Response Headers**
 	Accept-Ranges: bytes
 	Content-Length: 739
 	Content-Type: text/html
 	Date: Tue, 30 Jun 2020 07:53:36 GMT
 	ETag: "5e9bc167-2e3"
 	Last-Modified: Sun, 19 Apr 2020 03:11:35 GMT
 	Server: CSDN

- 建议大家选择第二种方式,虽然修改的文件以及操作可能多了点,但是第二种相对于第一种更安全一些。

原文链接:修复HTTP头信息泄露Nginx版本信息漏洞