天天看点

如何在Linux服务器中隐藏PHP版本

通常,大多数默认设置安装的web服务器存在信息泄露,这其中之一就是PHP。PHP 是如今流行的服务端html嵌入式语言(之一?)。在如今这个充满挑战的时代,有许多攻击者会尝试发现你服务端的漏洞。因此,我会简单描述如何在Linux服务器中隐藏PHP信息。

默认上expose_php默认是开的。关闭“expose_php”参数可以使php隐藏它的版本信息。

[[email protected] ~]#vi /etc/php.ini

在你的php.ini, 定位到含有expose_php的那行把On设成Off:

expose_php = Off

在此之前,web服务器头看上去就像这样:

[[email protected] ~]#curl -I http://www.ehowstuff.com/

HTTP/1.1 200 OK

Server: nginx

Content-Type:text/html; charset=UTF-8

Vary:Accept-Encoding

X-Powered-By:PHP/5.3.3

X-Pingback:http://www.ehowstuff.com/xmlrpc.php

Date: Wed, 11 Feb2015 14:10:43 GMT

X-Page-Speed:1.9.32.2-4321

Cache-Control:max-age=0, no-cache

更改并重启 Web 服务后,php就不会在web服务头中显示版本了:

HTTP/1.1 200 OK

Server: nginx

Content-Type:text/html; charset=UTF-8

Vary:Accept-Encoding

X-Powered-By:PHP/5.3.3

X-Pingback:http://www.ehowstuff.com/xmlrpc.php

Date: Wed, 11 Feb2015 14:10:43 GMT

X-Page-Speed:1.9.32.2-4321

Cache-Control:max-age=0, no-cache

LCTT译注:除了 PHP 的版本之外,Web 服务器也会默认泄露版本号。如果使用 Apache 服务器,请参照此文章关闭Apache 版本显示;如果使用 Nginx 服务器,请在 http 段内加入server_tokens off; 配置。以上修改请记得重启相关服务。

免费领取LAMP兄弟连原创PHP教程光盘/《细说PHP》精要版,详情咨询官网客服:http://www.lampbrother.net

PHPCMS二次开发 http://yun.itxdl.cn/online/phpcms/index.php?u=5

微信开发            http://yun.itxdl.cn/online/weixin/index.php?u=5

移动互联网服务器端开发   http://yun.itxdl.cn/online/server/index.php?u=5

Javascript课程   http://yun.itxdl.cn/online/js/index.php?u=5

CTO训练营                  http://yun.itxdl.cn/online/cto/index.php?u=5