隐藏或者混淆nginx默认返回header里边的Server:nginx

“在互联网中,我们要随时防止别人的渗透,所以我们要学会隐藏自己。” 我觉得说的对。于是我想把我的nginx返回的header里边的

Server: nginx

这个东西隐藏或者改成别的东西。

首先,找到源码里边的配置文件:src/http/ngx_http_header_filter_module.c
编辑49行:

static char ngx_http_server_string[] = "Server: nginx" CRLF;

如果想要混淆装杯就修改nginx字段:

static char ngx_http_server_string[] = "Server: jwdlh" CRLF;

如果想要把这个信息隐藏则直接改成双空就行,如果注释会编译报错:

static char ngx_http_server_string[] = ": " CRLF;

如果改版本号,src/core/nginx.h

#define NGINX_VERSION      "1.8.1"

改这个就行。

以上是源码编译之前的设置。但是我的nginx已经在运行了,那就需要更换了。

首先,nginx -V,把configure arguments:的值记录下来。

然后,到源码目录下进行重新编译。

./configure --xxxxxxxxxxxxx(刚才查到的编译参数)

然后make一下,注意 不要 make install,不然就覆盖安装现有nginx了。

make完之后在objs目录下就可以看到新编译的nginx文件了。测试一下:

./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

如果正常 那就没有问题。可以替换了。替换到安装目录下边的sbin/nginx
直接替换会报错:

cp: cannot create regular file ‘/usr/local/nginx/sbin/nginx’: Text file busy

因为旧nginx正在运行,无法替换
所以我们得停掉、备份、替换、启动。

运行成功,验证一下,效果达到。完美


版权声明:本文为qq791182650原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。