隐藏Nginx标识和版本号:彻底消除安全隐患
为了提升线上环境的安全性,常见的做法之一是隐藏Nginx的版本号,以减少潜在攻击者的信息收集。尽管可以通过 server_tokens off 参数来隐藏版本号,但这仍然会暴露当前使用的是Nginx服务。为了更彻底地解决这个问题,需要深入源代码进行处理。
背景
为提升线上环境的安全性,常见的做法之一是隐藏Nginx的版本号,以减少潜在攻击者的信息收集。尽管可以通过 server_tokens off 参数来隐藏版本号,但这仍然会暴露当前使用的是Nginx服务。为了更彻底地解决这个问题,需要深入源代码进行处理。以下介绍具体操作
下载源码
- 下载源码
BASH
1 | [root@C8_201 ~]# mkdir /opt/soft |
- 解压至当前目录
PLAINTEXT
1 | [root@C8_201 soft]# tar -zxvf nginx-1.16.1.tar.gz |
改源文件
- 我们将源码文件修改后,再进行编译安装
BASH
1 | [root@C8_201 soft]# cd nginx-1.16.1/ |
BASH
1 | ... |
BASH
1 | [root@C8_201 core]# cd .. |
BASH
1 | 49 static u_char ngx_http_server_string[] = "Server: nues" CRLF; |
BASH
1 | [root@C8_201 http]# vi ngx_http_special_response.c #修改第36行 |
BASH
1 | 35 static u_char ngx_http_error_tail[] = |
编译安装
BASH
1 | [root@C8_201 ~]# yum install -y gcc make zlib-devel pcre-devel openssl-devel |
BASH
1 | Configuration summary |
启动服务
BASH
1 | [root@C8_201 ~]# cd /usr/local/nginx/sbin/ |
关闭防火墙或放行80端口
BASH
1 | [root@C8_201 sbin]# firewall-cmd --permanent --zone=public --add-port=80/tcp |
验证效果
BASH
1 | [root@C8_201 sbin]# curl -I 127.0.0.1 |