在 CentOS 上配置 Apache(httpd)的端口,通常涉及修改监听端口、开放防火墙以及(如有)SELinux 设置。下面以 CentOS 7/8 为例说明。
Apache 的主配置文件通常位于:
/etc/httpd/conf/httpd.conf
找到并修改 Listen 指令,例如改为 8080:
Listen 8080
如果你使用了虚拟主机,也要检查:
/etc/httpd/conf.d/*.conf
例如:
<VirtualHost *:8080>
DocumentRoot /var/www/html
ServerName example.com
</VirtualHost>
httpd -t
systemctl restart httpd
CentOS 默认使用 firewalld。
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
firewall-cmd --list-ports
如果启用了 SELinux,必须允许 Apache 使用新端口。
semanage port -l | grep http_port_t
semanage port -a -t http_port_t -p tcp 8080
如果提示
semanage: command not found,先安装:yum install policycoreutils-python-utils
curl http://localhost:8080
浏览器访问:
http://服务器IP:8080
如果你使用的是 CentOS Stream / Rocky / Alma 或 Apache 2.4+,步骤基本一致。如果你有具体端口号或报错信息,可以发出来我帮你具体分析。