在Ubuntu上,Apache的内存限制可以通过修改Apache的配置文件来实现。以下是一些关键步骤和注意事项:
/etc/apache2/apache2.conf打开Apache的主配置文件:
sudo nano /etc/apache2/apache2.conf
StartServers、MinSpareServers、MaxSpareServers、MaxRequestWorkers和MaxConnectionsPerChild这些参数控制Apache的进程管理。例如:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 0
</IfModule>
StartServers: 启动时创建的服务器进程数。MinSpareServers: 最小空闲服务器进程数。MaxSpareServers: 最大空闲服务器进程数。MaxRequestWorkers: 同时处理请求的最大服务器进程数。MaxConnectionsPerChild: 每个服务器进程处理的最大请求数。mpm_event_module或mpm_worker_module如果你使用的是mpm_event_module或mpm_worker_module,配置方式略有不同。例如,对于mpm_event_module:
<IfModule mpm_event_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150
MaxConnectionsPerChild 0
</IfModule>
如果你使用PHP-FPM,还需要调整PHP的内存限制。编辑/etc/php/7.x/fpm/php.ini(根据你的PHP版本调整路径):
sudo nano /etc/php/7.x/fpm/php.ini
找到并修改以下行:
memory_limit = 128M
修改配置文件后,重启Apache服务以应用更改:
sudo systemctl restart apache2
通过以上步骤,你可以有效地调整Ubuntu上Apache的内存限制。