apache各類經常使用的配置

首先咱們編輯apache的虛擬配置文件,javascript

vim /usr/local/apache2/conf/extra/httpd-vhosts.conf,編輯或者添加這些內容css

 

<VirtualHost *:80>java

    ServerAdmin825536458@qq.comchrome

    DocumentRoot"/data/www/"apache

    ServerNamewww.test.comvim

ServerAlias www.hu.com緩存

##設置這些格式的東西不記錄到日誌app

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

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

    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

##設置域名跳轉

   <IfModulemod_rewrite.c>

           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]

</IfModule>

##設置網站的靜態緩存

 

<IfModule mod_expires.c>

   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"

</IfModule>

##設置防盜鏈

SetEnvIfNoCase Referer "^$" local_ref

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

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

<filesmatch"\.(txt|doc|mp3|zip|rar|jpg|gif|png|css|js)">

Order Allow,Deny

Allow from env=local_ref

</filesmatch>

##設置網站的訪問控制

<Directory "/data/www">

   AllowOverride None

    Options None

    Orderallow,deny

    Allow fromall

</Directory>

<filesmatch "(.*)admin(.*)">

      Orderdeny,allow

      Deny fromall

      deny from127.0.0.1

      allow from192.168.75.1

</filesmatch>

 

</VirtualHost>

相關文章
相關標籤/搜索