标签:apache
1.开启gzip功能<ifmodule mod_headers.c>
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=18000, public, must-reva lidate"
</FilesMatch>
<FilesMatch ".(html|htm|php)$">
Header set Cache-Control "max-age=3600, must-reva lidate"
</FilesMatch>
</ifmodule>
2.开启expires缓存
LoadModule expires_module modules/mod_expires.so
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A86400
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
ExpiresByType text/plain A604800
ExpiresByType application/x-shockwave-flash A604800
ExpiresByType video/x-flv A604800
ExpiresByType application/pdf A604800
ExpiresByType text/html A90000
<FilesMatch ".(gif|jpe?g|png)$">
Header set Cache-Control "max-age=604800"
Header unset ETag
</FilesMatch>
</IfModule>
3.开启模式配置
Include conf//extra/httpd-mpm.conf
vim /usr/local/apache/conf/extra/httpd-mpm.conf
<IfModule mpm_event_module>
StartServers 5
MinSpareThreads 100
MaxSpareThreads 200
ThreadsPerChild 50
ServerLimit 1000
MaxRequestWorkers 1000
MaxConnectionsPerChild 10000
</IfModule>
4.禁止目录遍历
Options Indexes(删除) FollowSymLinks
5.隐藏版本号
Include conf//extra/httpd-default.conf
vim httpd-default.conf
serversignature off
ServerTokens Prod
6.优化apache
vim httpd-default.conf
timeout 60 apache 写出数据到客户端连接的时间长度
keepalive on httpd 进程对每个请求的链接是否保持长链接
maxkeepaliverequests 100 最多保持多少个活动的长链接
keepalivetimeout 5 连接的保持时间,超过时间就回收
HostnameLookups Off 避免针对每个访问者的 DNS 域名的反向查询
7.防盗链
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !benet.com/.$ [NC]
RewriteCond %{HTTP_REFERER} !benet.com/.$ [NC]
RewriteCond %{HTTP_REFERER} !www.benet.com/.$ [NC]
RewriteCond %{HTTP_REFERER} !www.benet.com/.$ [NC]
RewriteRule .*.(gif|jpg|swf)$ http://www.benet.com/about/nolink.png [R,NC,L]
8.错误页面全部修改
ErrorDocument 402 /error-page.html
ErrorDocument 403 /error-page.html
ErrorDocument 404 /error-page.html
ErrorDocument 500 /error-page.html
ErrorDocument 501 /error-page.html
ErrorDocument 502 /error-page.html
9.禁止资源目录解析PHP程序
<Directory ~ “ /var/www/bbs/uploads”>
Options FollowSymLinks
AllowOverride None
Order allow, deny
Allow from all
php_flag engine off 添加这行
</Directory>
标签:apache
原文地址:http://blog.51cto.com/zuoshou/2119831