码迷,mamicode.com
首页 > Web开发 > 详细

apache各种常用的配置

时间:2015-10-10 12:40:25      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:apache的配置文件

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

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

 

<VirtualHost *:80>

    ServerAdmin825536458@qq.com

    DocumentRoot"/data/www/"

    ServerNamewww.test.com

ServerAlias www.hu.com

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

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

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

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

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

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

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

    SetEnvIfRequest_URI ".*\.css$" image-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=!image-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

   ExpiresByTypeimage/gif "access plus 1 days"

   ExpiresByTypeimage/jpeg "access plus 24 hours"

   ExpiresByTypeimage/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>


本文出自 “linux” 博客,请务必保留此出处http://825536458.blog.51cto.com/4417836/1701468

apache各种常用的配置

标签:apache的配置文件

原文地址:http://825536458.blog.51cto.com/4417836/1701468

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!