Nginx隐藏服务器端各类信息的方法
有时我们不希望有人可以通过一些工具来返回我们服务器的信息,下面我来介绍在nginx中隐藏nginx响应头,修改nginx返回头信息,隐藏php版本号,隐藏服务器信息,同学可参考。
首先隐藏nginx版本信息,只需编辑nginx.conf文件
添加一行
server_tokensoff;
http{
include/etc/nginx/mime.types;
default_typeapplication/octet-stream;
indexindex.phpindex.htmlindex.htm;
server_tokensoff;
log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent""$http_x_forwarded_for"';
access_log/var/log/nginx/access.logmain;
sendfileon;
#tcp_nopushon;
keepalive_timeout65;
#gzipon;
include/etc/nginx/conf.d/*.conf;
}
响应头隐藏PHP版本休息,编辑php.ini文件找到expose_php=On,修改为expose_php=Off
;;;;;;;;;;;;;;;;; ;Miscellaneous; ;;;;;;;;;;;;;;;;; ;DecideswhetherPHPmayexposethefactthatitisinstalledontheserver ;(e.g.byaddingitssignaturetotheWebserverheader).Itisnosecurity ;threatinanyway,butitmakesitpossibletodeterminewhetheryouusePHP ;onyourserverornot. ;http://www.php.net/manual/en/ini.core.php#ini.expose-php expose_php=Off