1、隐藏nginx header版本号
[root@ocbsap01 tmp]# curl -I 192.168.56.102:1983
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Thu, 20 Jul 2017 06:41:49 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 19 Jul 2017 07:46:59 GMT
Connection: keep-alive
ETag: "596f0e73-264"
Accept-Ranges: bytes
编译nginx.conf配置文件,添加server_tokens off参数
http {
...
server_tokens off; #控制http response header内的服务版本信息的显示,以及错误信息中web服务版本信息
...
}
[root@ocbsap01 ~]# curl -I 192.168.10.128:1983
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 25 Jul 2017 15:48:00 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Mon, 24 Jul 2017 16:16:38 GMT
Connection: keep-alive
ETag: "59761d66-264"
Accept-Ranges: bytes
2、更改源码隐藏软件名称需要修改三个nginx源码文件
第一个nginx-1.12.1/src/core/nginx.h文件
[root@ocbsap01 core]# pwd
/tmp/nginx-1.12.1/src/core
[root@ocbsap01 core]# vim nginx.h #将如下参数修改自定义的内容
#define NGINX_VERSION "1.12.1" #改成你想要的版本号,如2.4.2
#define NGINX_VER "nginx/" NGINX_VERSION #你想改成的软件名称,如Apache
#define NGINX_VAR "NGINX" #可以改成OWS等
第二个
vim /tmp/nginx-1.12.1/src/httpngx_http_header_filter_module.c
将这条static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
改成static u_char ngx_http_server_string[] = "Server: OWS" CRLF;
或者使用一条命令修改替换
[root@ocbsap01 nginx-1.12.1]# sed -i 's#Server: nginx#Server: OWS#g' src/http/ngx_http_header_filter_module.c
第三个ngx_http_special_response.c是否对外展示敏感信息
[root@ocbsap01 nginx-1.12.1]# sed -n '21,30p' src/http/ngx_http_special_response.c
static u_char ngx_http_error_full_tail[] =
"
"