首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 相關知識

Linux 伺服器隱藏 PHP 版本號:設定 expose_php = Off

     編輯:PHP 相關知識

Linux 伺服器隱藏 PHP 版本號:設定 expose_php = Off

預設 PHP 會在 HTTP 回應標頭發送 X-Powered-By: PHP/x.y.z,暴露版本資訊增加被攻擊風險。關閉 expose_php 即可隱藏。

操作步驟

  1. 編輯 php.ini:
    vi /etc/php.ini
  2. 尋找 expose_php,修改為:
    expose_php = Off
  3. 重啟 Web 伺服器(PHP-FPM / Apache / Nginx):
    systemctl restart php-fpm
    systemctl restart nginx

驗證前後差異

修改前

$ curl -I https://example.com/
HTTP/1.1 200 OK
Server: nginx
X-Powered-By: PHP/5.3.3
Content-Type: text/html; charset=UTF-8
...

修改後

$ curl -I https://example.com/
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=UTF-8
... (無 X-Powered-By 標頭)

補充安全建議

  • 同時隱藏 Nginx/Apache 版本:server_tokens off; (Nginx) / ServerTokens Prod (Apache)。
  • 關閉不必要的 PHP 函數:disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source。
  • 設定 open_basedir 限制腳本存取目錄。
  • 啟用 OPcache 並設定 opcache.validate_timestamps=0(生產環境)提升效能。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved