天天看點

如何在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教程CD光牒/《細說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