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>


你可能感兴趣的:(apache,域名跳转,配置用户认证)