nginx服务器隐藏版本号

来源:互联网 发布:js圆形进度条插件 编辑:程序博客网 时间:2024/06/05 21:54

1.隐藏Nginx版本号,Nginx的版本号主要在两个地方会有,一个是HTTP header,有个Server:nginx/1.x.x类似会暴露Web服务器所用软件名称以及版本号,这个也是大多数Web服务器最容易暴露版本号的地方,第二个地方是Nginx出错页面,比如404页面没有找到等,这是如果用户没有指定页面的话,那么Nginx自己的页面会有版本戳记。

http {    # ...省略一些配置    server_tokens off;}

最后别忘了使用命令nginx -s reload刷新当前配置。完成后你可以查看所有页面的响应头或者错误页,看看是不是只看到nginx字样而看不到版本号。


2.隐藏PHP的版本号,PHP容易暴露的版本号在什么地方呢?其实也是在HTTP头,以类似X-Powered-By: PHP/5.2.11这种形式存在,大家可能会想到会不会是Nginx问题,而去到Nginx里面找相关配置,呵呵,其实这个是在PHP的配置文件php.ini里改动,打开php.ini,找到下面叙述:

;;;;;;;;;;;;;;;;;; Miscellaneous ;;;;;;;;;;;;;;;;;;; Decides whether PHP may expose the fact that it is installed on the server; (e.g. by adding its signature to the Web server header).  It is no security; threat in any way, but it makes it possible to determine whether you use PHP; on your server or not.; http://php.net/expose-phpexpose_php = On

将expose_php = On改为expose_php = Off就搞定了,当然,对于Apache服务器还有另外一个方法可以直接尝试在.htaccess文件中Header unset X-Powered-By,删除X-Powered-By节,不过我还是建议改动php.ini的expose_php。

重启PHP的PHP-fpm:

pkill php-fpm/usr/local/php/sbin/php-fpm
原创粉丝点击