启用MPM模块
httpd.conf
,取消注释或添加:
LoadModule mpm_event_module modules/mod_mpm_event.so
mpm_winnt
模块调整MPM参数
httpd.conf
中添加或修改:
<IfModule mpm_winnt_module>
ThreadsPerChild 150
MaxConnectionsPerChild 0
</IfModule>
禁用不必要的模块
mod_negotiation
mod_autoindex
mod_userdir
mod_imagemap
启用压缩模块
mod_deflate
mod_filter
启用mod_expires
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresDefault "access plus 2 days"
</IfModule>
启用mod_headers
<IfModule mod_headers.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
</IfModule>
调整KeepAlive设置
KeepAlive On
KeepAliveTimeout 5
MaxKeepAliveRequests 100
关闭主机名查找
HostnameLookups Off
优化日志记录
启用Gzip压缩
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>
调整PHP配置
memory_limit
max_execution_time
定期清理日志
使用静态资源缓存
使用Apache的mod_status监控
<Location /server-status>
SetHandler server-status
Require local
</Location>
定期检查错误日志
压力测试
ab -n 1000 -c 100 http://yourdomain.com/
以上优化需要根据实际服务器配置和网站访问量进行调整,建议每次修改后测试性能变化并监控服务器资源使用情况。