1. 隐藏版本号
隐藏nginx的版本号很简单,nginx的HttpCoreModule提供了一条叫做server_tokens指令,我这要将这条指令设置为“server_tokens off”就可以了。
nginx -s reload
再次访问,nginx没有了版本号
2. 如果要修改nginx的版本号,可以进行Nginx修改源码如下:
然后我们重新预编译,编译,安装即可,
$./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_ssl_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-http_sysguard_module --with-http_concat_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
$make
$make install
我们再次打开,发现我们的nginx版本改成了 我定义的 "knight" 了
3. 隐藏 Tengine的版本号
有时候我们访问一个不存在的url会有如下的提示:
解决方法为:
sudo vim /etc/nginx/conf/public_config/basic.conf
server_info off;
server_tokens off;