Apache优化配置总结

Apache下载:http://httpd.apache.org/download.cgi


../conf/httpd.conf

分别搜索关键字ServerTokens和ServerSignature,修改:

ServerTokens OS 修改为 ServerTokens ProductOnly
ServerSignature On 修改为 ServerSignature Off





<IfModule worker.c>
ThreadLimit 128
ServerLimit 32
StartServers 10
MaxClients 4096
MinSpareThreads 128
MaxSpareThreads 512
ThreadsPerChild 128
MaxRequestsPerChild 5000
</IfModule>


LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so    
AddOutputFilterByType DEFLATE text/html text/plain text/xml
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate 
CustomLog logs/deflate_log deflate
<Location />
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpg|cab|jpe?g|exe|bmp|pdf|mp3|rar|zip|swf|png)$ no-gzip dont-vary 
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>


LoadModule expires_module modules/mod_expires.so 
LoadModule headers_module modules/mod_headers.so
<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE    
    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|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary
    AddOutputFilterByType DEFLATE text/* 
    AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript 
    AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp 
    BrowserMatch ^Mozilla/4 gzip-only-text/html 
    BrowserMatch ^Mozilla/4.0[678] no-gzip 
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
</IfModule>


上边一段的说明<IfModule mod_deflate.c>中

SetOutputFilter DEFLATE    #必须的,就像一个开关一样,告诉apache对传输到浏览器的内容进行压缩
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary #设置不对后缀gif,jpg,jpeg,png的图片文件进行压缩
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary #同上,就是设置不对exe,tgz,gz。。。的文件进行压缩
SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary
AddOutputFilterByType DEFLATE text/* #设置对文件是文本的内容进行压缩,例如text/html  text/css  text/plain等
AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript #这段代码你只需要了解application/javascript application/x-javascript这段就可以了,这段的意思是对javascript文件进行压缩
AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp #这段是告诉apache对php类型的文件进行压缩
BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.x 有一些问题,所以只压缩文件类型是text/html的
BrowserMatch ^Mozilla/4.0[678] no-gzip # Netscape 4.06-4.08 有更多的问题,所以不开启压缩
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # IE浏览器会伪装成 Netscape ,但是事实上它没有问题


LoadModule expires_module modules/mod_expires.so 

<IfModule mod_expires.c> 
ExpiresActive On
ExpiresByType image/* A25920000
ExpiresByType text/html A6048000 
ExpiresByType text/css A9072000 
ExpiresByType application/x-javascript A7060000 
ExpiresByType text/javascript A7060000 
ExpiresDefault A6048000
</IfModule>


LoadModule jk_module modules/mod_jk.so

#JkWorkersFile conf/workers.properties
#JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE, 
JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format 
JkRequestLogFormat     "%w %V %T"



<VirtualHost *:80>
AddType text/javascript;charset=UTF-8 .js
AddType text/css;charset=UTF-8 .css

DocumentRoot "D:/Tomcat6.0/webapps/"
ServerName 127.0.0.1
Alias /webtest "D:/Tomcat6.0/webapps/webtest"
DirectoryIndex index.jsp index.htm index.html default.htm   

      <Directory "D:/Tomcat6.0/webapps/">
          Options Indexes MultiViews
          AllowOverride None
          Order allow,deny
          Allow from all
      </Directory>
#JkAutoAlias "D:/Tomcat6.0/webapps/"
#JkMount /*.jsp ajp13
JkMount /webtest/*.jsp ajp13
JkMount /webtest/center.do ajp13
</VirtualHost>


#ErrorLog "logs/error.log"

# 限制错误日志文件为 1M
ErrorLog "|bin/rotatelogs.exe -l logs/error-%Y-%m-%d.log 1M"

# 每天生成一个错误日志文件
ErrorLog "|bin/rotatelogs.exe -l logs/error-%Y-%m-%d.log  86400"

# 限制访问日志文件为 1M
CustomLog "|bin/rotatelogs.exe -l D:/apachelogs/access-%Y-%m-%d.log 1M" common

# 每天生成一个访问日志文件
CustomLog "|bin/rotatelogs.exe -l D:/apachelogs/access-%Y-%m-%d.log 86400" common


<Directory />
    Options None(190行左右)
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

你可能感兴趣的:(apache)