Nginx的版本号隐藏

Nginx的版本号相关

隐藏版本号

nginx隐藏版本号需要将主配置文件中server_tokens关闭

server_tokens off;

查看头信息

[root@www ~]# curl -I  www.mylinuxops.com
HTTP/1.1 200 OK
Server: nginx           #现在已经不显示nginx的版本号了
Date: Fri, 31 May 2019 12:32:23 GMT
Content-Type: text/html
Content-Length: 15
Last-Modified: Thu, 30 May 2019 15:33:51 GMT
Connection: keep-alive
Keep-Alive: timeout=65
ETag: "5ceff7df-f"
Accept-Ranges: bytes

彻底隐藏server信息

如果需要彻底的隐藏server信息,连nginx都不显示就需要修改源码
将源码包内的ngx_http_header_filter_module.c文件进行修改
1.修改源码

[root@www nginx-1.14.2]# vim src/http/ngx_http_header_filter_module.c
#static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
static u_char ngx_http_server_string[] = "Server: " CRLF;
#将此文件内的第49行中的server之后的部分全部删除,然后重新编译

2.检查编译环境及工具

[root@www nginx-1.14.2]# ./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/root/echo-nginx-module

3.生成相应模块并复制模块到指定目录

[root@www nginx-1.14.2]# make && make install

4.启动服务

[root@www nginx-1.14.2]# systemctl start nginx

5.再次查看头信息

[root@www nginx-1.14.2]# curl -I www.mylinuxops.com
HTTP/1.1 200 OK
Server:             #server信息已经彻底的隐藏
Date: Fri, 31 May 2019 12:50:10 GMT
Content-Type: text/html
Content-Length: 15
Last-Modified: Thu, 30 May 2019 15:33:51 GMT
Connection: keep-alive
Keep-Alive: timeout=65
ETag: "5ceff7df-f"
Accept-Ranges: bytes

转载于:https://blog.51cto.com/11886307/2403932

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值