MXOXW

Life always finds a way.

nginx修改server header

| Comments

nginx自定义server
修改nginx的名称,隐藏版本号,既增加安全性又可以用来装逼。
nginx展示名称的地方,通常有Response Header中的server,错误页等。

修改几个位置如下:

修改src/core/nginx.h

1
2
#define NGINX_VERSION      "1.12.1"
#define NGINX_VER "NGINX/" NGINX_VERSION

修改src/http/ngx_http_header_filter_module.c

1
static u_char ngx_http_server_string[] = "Server: nginx" CRLF;

修改src/http/ngx_http_special_response.c

1
2
3
4
5
static u_char ngx_http_error_tail[] =
"<hr><center>nginx</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

对于http2,还需要修改

修改src/http/v2/ngx_http_v2_filter_module.c

1
static const u_char nginx[5] = "\x84\xaa\x63\x55\xe7";

此处的内容经过压缩编码,可以使用工具HPACK-Encode转换。
已经编译过的,可以直接下载go.zip
使用方法

1
go.exe "nginx"

重新编译nginx

1
nginx -V

查看对应的nginx版本,以及编译配置信息

1
2
./configure ......
make

完成之后,杀掉所有nginx进程

1
2
killall nginx
killall nginx

备份之前的版本

1
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

用新版本替换

1
cp ./objs/nginx /usr/local/nginx/sbin/

重启

1
nginx

以上

评论