如何进行CentOS系统Apache服务器优化
如何进行CentOS系统Apache服务器优化
1. 修改httpd.conf
打开/etc/httpd/conf/httpd.conf文件,修改如下参数:
ServerTokens Prod
ServerSignature Off
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 512
MaxClients 512
MaxRequestsPerChild 4000
StartServers 4
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 512
MaxRequestsPerChild 0
2. 修改PHP配置
打开/etc/php.ini文件,修改如下参数:
expose_php = Off
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ERROR | E_WARNING | E_PARSE
display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = /var/log/php_errors.log
post_max_size = 8M
upload_max_filesize = 2M
max_file_uploads = 20
date.timezone = Asia/Shanghai
3. 开启Apache的gzip压缩
打开/etc/httpd/conf/httpd.conf文件,在最后面添加以下内容:
SetOutputFilter DEFLATE
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript application/javascript
4. 开启Apache的缓存
打开/etc/httpd/conf/httpd.conf文件,在最后面添加以下内容:
ExpiresActive On
ExpiresDefault "access plus 30 seconds"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 year"
5. 开启Apache的keep-alive
打开/etc/httpd/conf/httpd.conf文件,修改如下参数:
KeepAlive On
KeepAliveTimeout 3
MaxKeepAliveRequests 200
6. 开启Apache的mod_headers模块
打开/etc/httpd/conf/httpd.conf文件,修改如下参数:
Header set Connection keep-alive
7. 修改Apache的MIME类型
打开/etc/httpd/conf/mime.types文件,添加以下内容:
application/javascript js
application/x-javascript js
8. 开启Apache的mod_deflate模块
打开/etc/httpd/conf/httpd.conf文件,修改如下参数:
SetOutputFilter DEFLATE
9. 修改Apache的KeepAliveTimeout
打开/etc/httpd/conf/httpd.conf文件,修改如下参数:
KeepAliveTimeout 5
10. 使用Etag
打开/etc/httpd/conf/httpd.conf文件,修改如下参数:
FileETag None
相关文章