apache 配置用户认证 域名跳转 日志 静态缓存文件 防盗链接
配置文件:/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 24 hours"
ExpiresByType image/png "access plus 24 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>
本文出自 “david0512” 博客,请务必保留此出处http://gjr0512.blog.51cto.com/6518687/1651913
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。