转载自:https://blog.csdn.net/z13615480737/article/details/79024252
----------------------------------------------------------------------------------------------------------------
在生产环境中暴露WEB服务器的名称和版本信息这些信息是不安全的。通过两种方式对上述信息进行隐藏:
一 、是在配置文件中加入server_tokens off; 参数禁止版本信息泄漏:
1.启动nginx /usr/local/nginx/sbin/nginx
可以看到我本地的nginx是1.12版本的
去掉版本信息 在nginx的配置文件 中添加
vim /usr/local/nginx/conf/nginx.conf
server_tokens off;
重启nginx
这种情况下只能隐藏版本,不能隐藏文件名。
第二种办法是在编译的时候把源文件里的版本信息更改一下,
编译完后显示的是你修改的内容。
修改源码包里的三个文件:1.src/core下的nginx.h文件
#define nginx_version 101010
#define NGINX_VERSION "7.88"
#define NGINX_VER "SSI/" NGINX_VERSION
static char ngx_http_server_string[] = "Server: SSI" CRLF;
static u_char ngx_http_error_tail[] =
"<hr><center>SSI</center>" CRLF
重新编译nginx:
make clean
./configure --prefix=/usr/local/nginx
make && make install