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
相关推荐
fuyongliang12337 分钟前
nginx反向代理,负载均衡,tomcat的数据流向图篇解析
nginx·tomcat·负载均衡
tuokuac1 小时前
nginx配置前端请求转发到指定的后端ip
前端·tcp/ip·nginx
LUCIAZZZ3 小时前
HTTPS优化简单总结
网络·网络协议·计算机网络·http·https·操作系统
青草地溪水旁4 小时前
http response的工作流程详细解析
网络协议·http·应答
凉伊5 小时前
HTTP 协议:从原理到应用的深度剖析
网络·网络协议·http
苹果醋35 小时前
数据库索引设计:在 MongoDB 中创建高效索引的策略
java·运维·spring boot·mysql·nginx
✎﹏赤子·墨筱晗♪7 小时前
从反向代理到负载均衡:Nginx + Tomcat 构建高可用Web服务架构
nginx·tomcat·负载均衡
叶绪2587 小时前
Nginx 反向代理 + Tomcat 集群:负载均衡配置步骤与核心原理
nginx·tomcat·负载均衡
2501_915918417 小时前
iOS 开发全流程实战 基于 uni-app 的 iOS 应用开发、打包、测试与上架流程详解
android·ios·小程序·https·uni-app·iphone·webview
杏花春雨江南10 小时前
腾讯云 CLB (Cloud Load Balancer) 为例,详细讲解如何配置 Nginx 集群
nginx·云计算·腾讯云