Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

隱藏 Nginx 與 PHP 版本號提升伺服器安全性

編輯:Linux 教學

為什麼要隱藏版本資訊?

HTTP 響應頭中的 Server 與 X-Powered-By 會洩露軟體版本,攻擊者可據此針對已知漏洞發起攻擊。隱藏版本號是基礎加固措施之一。

Nginx 隱藏版本號

編輯 nginx.conf 的 http 區塊,加入或修改:

http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;          # 關鍵:關閉版本號顯示
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 50m;
    # ... 其他配置
}

PHP 隱藏版本號

編輯 php.ini,找到 expose_php 項並設為 Off:

expose_php = Off

重新載入服務生效

# PHP-FPM
/usr/local/php/sbin/php-fpm restart

# Nginx 平滑重載
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

驗證結果

使用 curl -I https://your-domain.com 檢查響應頭,確認不再包含 Server: nginx/x.x.x 與 X-Powered-By: PHP/x.x.x。

Copyright © Windows教程網 All Rights Reserved