修改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