Configuration file:/usr/local/apache2/conf/extra/httpd-vhosts.conf
<virtualhost *:80>
ServerAdmin [email protected]
DocumentRoot "/data/www"
ServerName www.1.com
Serveralias www.a.com www.b.com
#配置用户认证
<Directory/data/www>
allowoverride authconfig
AuthName "132"
authtype Basic
authuserfile/data/.htpasswd
require Valid-user
</Directory>
#配置域名跳转
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond%{http_host} ^www.a.com$ [OR]
Rewritecond%{http_host} ^www.b.com$
Rewriterule ^/(. *) $ http://www.1.com/$1 [r=301,l]
</IfModule>
#配置日志
Errorlog "/usr/local/apache2/logs/error.log"
Setenvif Request_uri ". *\.gif$" Image-request
Setenvif Request_uri ". *\.jpg$" Image-request
Setenvif Request_uri ". *\.png$" Image-request
Setenvif Request_uri ". *\.bmp$" Image-request
Setenvif Request_uri ". *\.swf$" Image-request
Setenvif Request_uri ". *\.js$" Image-request
Setenvif Request_uri ". *\.css$" Image-request
Customlog "|/usr/local/apache2/bin/rotatelogs-l/usr/local/apache2/logs/1.com-access_%y%m%d.log 86400" combined env =!image-request
#配置静态文件缓存
<ifmodule mod_expires.c>
Expiresactive on
Expiresbytype image/gif "Access plus 1 days"
Expiresbytype image/jpeg "Access plus hours"
Expiresbytype image/png "Access plus hours"
Expiresbytype text/css "Now plus 2 hour"
Expiresbytype Application/x-javascript "now plus 2 hours"
Expiresbytype Application/javascript "now plus 2 hours"
Expiresbytype Application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
</IfModule>
#配置防盗链接
Setenvifnocase Referer "^http://www.1.com" Local_ref
Setenvifnocase Referer "www.a.com" Local_ref
Setenvifnocase Referer "www.b.com" Local_ref
Setenvifnocase Referer "^$" Local_ref
<filesmatch "\. (txt|doc|mp3|zip|rar|jpg|gif) ">
Order Allow,deny
Allow from Env=local_ref
</filesmatch>
</VirtualHost>
This article is from the "david0512" blog, make sure to keep this source http://gjr0512.blog.51cto.com/6518687/1651913
Apache Configure user authentication domain name jump log static cache file anti-theft link