在 Debian 上用 Apache 做“负载”,通常有两种理解,我分别说明,你可以按需选择:
如果你是想让 单台 Debian + Apache 扛更多请求:
apt install apache2
a2query -M
常见 MPM:
prefork:稳定但耗内存(适合老 PHP)worker:多线程,性能更好event:高并发首选(推荐)切换:
a2dismod mpm_prefork
a2enmod mpm_event
systemctl restart apache2
编辑:
/etc/apache2/mods-enabled/mpm_event.conf
示例(4核8G):
<IfModule mpm_event_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 5000
</IfModule>
/etc/apache2/conf-enabled/keepalive.conf
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
a2enmod deflate expires
配合 Nginx 或 CDN 效果更好。
如果你是想要 Apache 把请求分发到多台后端服务器:
a2enmod proxy proxy_http proxy_balancer lbmethod_byrequests headers
systemctl restart apache2
示例(轮询):
<VirtualHost *:80>
ServerName example.com
<Proxy "balancer://mycluster">
BalancerMember "http://192.168.1.10:8080"
BalancerMember "http://192.168.1.11:8080"
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass "/" "balancer://mycluster/"
ProxyPassReverse "/" "balancer://mycluster/"
</VirtualHost>
byrequests:轮询(默认)bytraffic:按流量bybusyness:按忙碌程度BalancerMember "http://192.168.1.10:8080" status=+H
✅ 推荐生产架构:
用户 → Nginx/Apache(负载) → Tomcat / Node / PHP
如果你愿意,可以告诉我:
我可以直接给你一份可直接用的配置。