nginx安装升级修复HTTP头信息泄露Nginx版本信息漏洞(并保持https配置)

文章目录

  • [1. 准备工作](#1. 准备工作)
  • [2. 修改web服务器所使用的nginx的名称和版本信息](#2. 修改web服务器所使用的nginx的名称和版本信息)
    • [2.1 修改以下三个文件:](#2.1 修改以下三个文件:)
      • [(1) ·src/core目录下的nginx.h文件](#(1) ·src/core目录下的nginx.h文件)
      • [(2) ·src/http目录下的ngx_http_header_filter_module.c文件](#(2) ·src/http目录下的ngx_http_header_filter_module.c文件)
      • [(3) ·src/http目录下的ngx_http_special_response.c文件](#(3) ·src/http目录下的ngx_http_special_response.c文件)
  • [2.2 重新编译nginx](#2.2 重新编译nginx)
  • [2.3 nginx启停命令](#2.3 nginx启停命令)
  • 2.4浏览器控制台抓包可以看到:

1. 准备工作

(1)下载最新稳定版nginx包

官网下载地址:https://nginx.org/en/download.html![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/bb4dbd80e1f2471aac035b7882492a60.png)

(2)将nginx包拷贝到服务器并解压(# 解压到当前目录下tar -zxvf 资源包)
(3)备份服务器nginx.conf文件、ssl证书文件

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

2.1 修改以下三个文件:

(1) ·src/core目录下的nginx.h文件

xml 复制代码
 #define NGINX_VERSION   "" 
 #define NGINX_VER   "CSDN" NGINX_VERSION

(2) ·src/http目录下的ngx_http_header_filter_module.c文件

xml 复制代码
 static u_char ngx_http_server_string[] = "Server: CSDN" CRLF;

(3) ·src/http目录下的ngx_http_special_response.c文件

xml 复制代码
 static u_char ngx_http_error_tail[] =
 "<hr><center>CSDN</center>" CRLF
 "</body>" CRLF
 "</html>" CRLF

2.2 重新编译nginx

(1)进入安装包目录:/home/nginx1.16.1

(2)./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

(3)make && make install

2.3 nginx启停命令

xml 复制代码
 cd /usr/local/nginx/sbin/
./nginx   #启动
./nginx -s stop  #停止
./nginx -s quit  #退出
./nginx -s reload  #重启  修改配置后重新加载生效
./nginx -s reopen :重新打开日志文件

2.4浏览器控制台抓包可以看到:

xml 复制代码
HTTP/1.1 200
Server: CSDN
Date: Wed, 03 Jul 2024 09:40:49 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
相关推荐
若云止水1 小时前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
一只小姜丝3321 小时前
解决各大浏览器中http地址无权限调用麦克风摄像头问题
网络·vue.js·网络协议·http
浪九天4 小时前
Nginx系列05(负载均衡、动静分离)
nginx·运维开发·持续部署
m0_748252389 小时前
Node.js HTTP模块详解:创建服务器、响应请求与客户端请求
服务器·http·node.js
m0_7482365811 小时前
Nginx中$http_host、$host、$proxy_host的区别
运维·nginx·http
Ljw...13 小时前
HTTP
linux·网络·网络协议·http
web1478621072313 小时前
Linux(CentOS)安装 Nginx
linux·nginx·centos
追风赶月、13 小时前
【网络】HTTPS协议原理
网络·网络协议·https
桃酥40315 小时前
8、HTTP/1.0和HTTP/1.1的区别【高频】
网络·http