Nginx修改server版本号


修改server字段
如果想自定义响应报文的nginx版本信息,需要修改源码文件,重新编译
如果nginx配置文件中的字段设定为server_tokens on,请修改 src/core/nginx.h 修改13-14行,如下示例
[root@centos8-1 nginx-1.18.0]$pwd
/usr/local/src/nginx-1.18.0
[root@centos8-1 nginx-1.18.0]$vim src/core/nginx.h
#define NGINX_VERSION "1.1999"     ##自定义修改版本号
#define NGINX_VER "zhanginx/" NGINX_VERSION   ##自定义修改版本信息

如果nginx配置文件中的字段设定为server_tokens on,请修改 src/http/ngx_http_header_filter_module.c
第49行,如下示例:
static u_char ngx_http_server_string[] = "Server: zhanginx" CRLF;   

####自定义修改版本
修改完之后回到nginx源码包里面,然后重新编译即可

[root@centos8-1 nginx-1.18.0]$nginx -V   ##编译完成测试
nginx version: zhanginx/1.1999

[root@centos8-2 ~]$curl 10.0.0.8/test.php -I     ##编译完成测试
HTTP/1.1 200 OK
Server: zhanginx
Date: Fri, 25 Sep 2020 03:31:08 GMT
Content-Type: text/html
Content-Length: 20
Last-Modified: Fri, 25 Sep 2020 03:18:08 GMT
Connection: keep-alive
ETag: "5f6d6170-14"
Accept-Ranges: bytes

 注:src路径是在nginx源码包解压完成cd进去的   

Nginx编译可参考:https://www.cnblogs.com/tz66/p/13728479.html

posted @ 2020-09-25 11:55  练习生天泽  阅读(1309)  评论(0编辑  收藏  举报