在 CentOS 上加速 Apache(httpd)通常从系统层、Apache 配置、PHP/应用层、缓存与前端几个方向入手。下面按实用程度给你一套常见优化方案。
systemctl disable --now postfix
systemctl disable --now firewalld # 如有外部防火墙可关
ulimit -n 65535
永久生效:
/etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
配置文件一般在:
/etc/httpd/conf/httpd.conf/etc/httpd/conf.modules.d/httpd -V | grep MPM
推荐 event(CentOS 默认可能是 prefork):
LoadModule mpm_event_module modules/mod_mpm_event.so
<IfModule mpm_event_module>
StartServers 4
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 10000
</IfModule>
PHP 如果是 mod_php,不能用 event,要用 php-fpm
sudo yum install -y mod_deflate
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css application/javascript
</IfModule>
sudo yum install -y mod_expires
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
</IfModule>
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
yum install -y php-fpm
systemctl enable --now php-fpm
Apache 使用:
yum install -y mod_proxy_fcgi
ProxyPassMatch ^/(.*\.php)$ unix:/run/php-fpm/www.sock|fcgi://localhost/var/www/html/$1
yum install -y php-opcache
; php.ini
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=4000
常见架构:
Nginx (静态) → Apache (动态)
ab -n 1000 -c 100 http://yourdomain.com/
✅ event MPM
✅ mod_deflate
✅ mod_expires
✅ php-fpm + opcache
✅ KeepAlive
如果你愿意,可以告诉我:
我可以给你定制一套配置。