在 CentOS 上通常使用的是 Apache HTTP Server(httpd),而不是 apache2(那是 Debian/Ubuntu 的叫法)。你提到“访问慢”,一般可以从下面几类原因排查。
Apache 默认会尝试对客户端 IP 做 反向 DNS 解析。
现象
解决 编辑 Apache 配置:
vi /etc/httpd/conf/httpd.conf
修改或添加:
HostnameLookups Off
重启:
systemctl restart httpd
CentOS 默认开启 SELinux。
检查
getenforce
如果是 Enforcing,可临时测试:
setenforce 0
如果变快了,说明是 SELinux 策略问题。
正确做法(不关 SELinux)
setsebool -P httpd_can_network_connect 1
mod_reqtimeout / 连接被拖死某些客户端连接不释放,导致 worker 被占满。
检查当前模式
httpd -M | grep mpm
如果是 prefork(默认):
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 1000
</IfModule>
如果跑的是 PHP 网站:
开启 OPcache(PHP 7+)
yum install php-opcache
php.ini:
opcache.enable=1
top
iostat -x 1
如果 %wa 很高,说明磁盘慢。
查看当前连接:
ss -ant | grep :80 | wc -l
# 1. 关闭 DNS 解析
HostnameLookups Off
# 2. 看错误日志
tail -f /var/log/httpd/error_log
# 3. 看访问日志
tail -f /var/log/httpd/access_log
# 4. 测试本地访问
curl -I http://127.0.0.1
✅ 99% 是 DNS 反向解析 或 PHP 未缓存
你可以补充:
我可以直接帮你给出 针对性配置。