首先我们编辑apache的虚拟配置文件,

vim /usr/local/apache2/conf/extra/httpd-vhosts.conf,编辑或者添加这些内容

 

    [email protected]

    DocumentRoot"/data/www/"

    ServerNamewww.test.com

ServerAlias www.hu.com

##设置这些格式的东西不记录到日志

    SetEnvIfRequest_URI ".*\.gif$" p_w_picpath-request

    SetEnvIfRequest_URI ".*\.jpg$" p_w_picpath-request

    SetEnvIfRequest_URI ".*\.png$" p_w_picpath-request

    SetEnvIfRequest_URI ".*\.bmp$" p_w_picpath-request

    SetEnvIfRequest_URI ".*\.swf$" p_w_picpath-request

    SetEnvIfRequest_URI ".*\.js$" p_w_picpath-request

    SetEnvIfRequest_URI ".*\.css$" p_w_picpath-request

    ErrorLog"logs/test.com-error_log"

CustomLog"|/usr/local/apache2/bin/rotatelogs -l/usr/local/apache2/logs/test.com-access_%Y%m%d_log 86400" combinedenv=!p_w_picpath-request   ##(切割每天的日志文件格式是年--_log

##设置域名跳转

  

           RewriteEngine on

           RewriteCond %{HTTP_HOST} ^www.hu.com$

           RewriteRule ^/(.*)$ http://www.test.com/$1 [R=301,L]

##user_agent的设置

           #rewritecond %{http_user_agent} ^.*curl.* [nc,or]

           #rewritecond %{http_user_agent} ^.*chrome.* [nc] 

           #rewriterule .*  - [F]

           RewriteCond %{REQUEST_URI} ^.*/tmp/.* [NC]

          rewriterule .*  - [F]

##设置网站的静态缓存

 

   ExpiresActiveon

   ExpiresByTypep_w_picpath/gif "access plus 1 days"

   ExpiresByTypep_w_picpath/jpeg "access plus 24 hours"

   ExpiresByTypep_w_picpath/png "access plus 24 hours"

   ExpiresByTypetext/css "now plus 2 hours"

   ExpiresByTypeapplication/x-javascript "now  plus2 hours"

   ExpiresByTypeapplication/x-shockwave-flash "now plus 2 hours"

  ExpiresDefault "now plus 0 min"

##设置防盗链

SetEnvIfNoCase Referer "^$" local_ref

SetEnvIfNoCase Referer"^http://.*\.test\.com" local_ref

SetEnvIfNoCase Referer ".*\.blog.51cto\.com"local_ref

Order Allow,Deny

Allow from env=local_ref

##设置网站的访问控制

   AllowOverride None

    Options None

    Orderallow,deny

    Allow fromall

      Orderdeny,allow

      Deny fromall

      deny from127.0.0.1

      allow from192.168.75.1