Nginx的版本号相关
隐藏版本号
nginx隐藏版本号需要将主配置文件中server_tokens关闭
server_tokens off;
查看头信息
[[email protected] ~]# 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.修改源码
[[email protected] 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.检查编译环境及工具
[[email protected] 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.生成相应模块并复制模块到指定目录
[[email protected] nginx-1.14.2]# make && make install
4.启动服务
[[email protected] nginx-1.14.2]# systemctl start nginx
5.再次查看头信息
[[email protected] 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
时间: 2024-09-28 07:21:29