在 CentOS 上隐藏 Apache(httpd)版本号,可以通过修改 Apache 的配置文件来实现。下面是推荐且安全的做法。
CentOS 中 Apache 的配置文件通常位于:
/etc/httpd/conf/httpd.conf
使用编辑器打开:
vim /etc/httpd/conf/httpd.conf
在文件末尾或合适位置添加:
ServerTokens Prod
ServerSignature Off
✅ 说明:
ServerTokens ProdServerSignature Offsystemctl restart httpd
或(旧版本):
service httpd restart
curl -I http://localhost
✅ 修改前可能看到:
Server: Apache/2.4.6 (CentOS)
✅ 修改后应看到:
Server: Apache
访问一个不存在的 URL,确认错误页面中 没有 Apache 版本信息。
⚠️ 以下方法不推荐新手使用,需要重新编译 Apache:
mod_security / 反向代理(Nginx)如果只是安全加固,ServerTokens Prod + ServerSignature Off 已足够。
yum update httpd
Options -Indexes
如果你使用的是 CentOS 7 / 8 / Stream 或 Apache 2.4.x,我也可以给你一份完整的安全加固配置示例。