php apache优化,apache优化

1.开启gzip功能

ln -s /usr/local/zlib/lib/libz.so /usr/lib/

LoadFile /usr/lib64/libz.so

LoadModule deflate_module modules/mod_deflate.so

LoadModule headers_module modules/mod_headers.so

DeflateCompressionLevel 6

AddOutputFilterByType DEFLATE text/plain

AddOutputFilterByType DEFLATE text/html

AddOutputFilterByType DEFLATE text/php

AddOutputFilterByType DEFLATE text/xml

AddOutputFilterByType DEFLATE text/css

AddOutputFilterByType DEFLATE text/javascript

AddOutputFilterByType DEFLATE application/xhtml+xml

AddOutputFilterByType DEFLATE application/xml

AddOutputFilterByType DEFLATE application/rss+xml

AddOutputFilterByType DEFLATE application/atom_xml

AddOutputFilterByType DEFLATE application/javascript

AddOutputFilterByType DEFLATE application/x-javascript

AddOutputFilterByType DEFLATE application/x-httpd-php

AddOutputFilterByType DEFLATE image/svg+xml

BrowserMatch ^Mozilla/4 gzip-only-text/html

BrowserMatch ^Mozilla/4.0[678] no-gzip

BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

SetEnvIfNoCase Request_URI .(?:html|htm)$ no-gzip dont-varySetEnvIfNoCase

SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary

SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary

SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no-gzip dont-vary

Header set Cache-Control "max-age=604800, public"

Header set Cache-Control "max-age=18000, public, must-reva lidate"

Header set Cache-Control "max-age=3600, must-reva lidate"

2.开启expires缓存

LoadModule expires_module modules/mod_expires.so

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

Header set Cache-Control "max-age=604800"

Header unset ETag

3.开启模式配置

Include conf//extra/httpd-mpm.conf

vim /usr/local/apache/conf/extra/httpd-mpm.conf

StartServers 5

MinSpareThreads 100

MaxSpareThreads 200

ThreadsPerChild 50

ServerLimit 1000

MaxRequestWorkers 1000

MaxConnectionsPerChild 10000

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程序

Options FollowSymLinks

AllowOverride None

Order allow, deny

Allow from all

php_flag engine off 添加这行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值