<VirtualHost *:80>
DocumentRoot "/data/wwww/"
ServerName www.test1.com
ServerAlias www.aaaaaa.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/www/"
ServerName www.test.com
ServerAlias www.aaa.com
ServerAlias www.bbb.com
ErrorLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/www.test.com-error__%Y%m%d_log 86400"
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/www.test.com-access_%Y%m%d_log 86400" combine env=!image-request
#apache用户认证
<Directory /data/www/abc>
AllowOverride Authconfig
AuthName "Wonderfule"
AuthType Basic
AuthUserFile /data/.htpaaswd
require valid-user
</Directory>
#301跳转,需要启动rewrite_module
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.aaa.com$ [OR]
Rewritecond %{HTTP_HOST} ^www.bbb.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]
#--------------------------------------------------------------------
#------- Apache通过rewrite限制访问某个目录
# RewriteCond %{REQUEST_URI} ^.*/data/.* [NC,OR]
# RewriteCond %{REQUEST_URI} ^.*/tmp/.* [NC]
# RewriteRule .* - [F]
---------------------------------------------------------------------
</IfModule>
#静态缓存设置
<Ifmodule mod_expires.c>
ExpiresActive on
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpeg "access plus 24 hours"
ExpiresByType iamge/png "access plus 24 hours"
ExpiresByType text/css "now plus 2 hour"
ExpiresByType application/x-javescript "now plus 2 hour"
ExpiresByType application/x-shockwave-flash "now plus 2 hour"
ExpiresDefault "now plus 0 min"
</Ifmodule>
#配置防盗链
SetEnvIfNoCase Referer "^http://.*\.test\.com" local_ref
<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png|js|css)">
Order deny,allow
Deny from all
Allow from env=local_ref
</filesmatch>
#配置网站访问黑名单
<Directory "/data/www">
AllowOverride None
options None
Order allow,deny
Allow from all
Deny from 192.168.1.17 #这样写deny生效 allow写在deny前面
</Directory>
#配置网站访问白名单
<filesmatch "(.*)admin(.*)">
Order deny,allow
Deny from all
Allow from 127.0.0.1
Allow from 192.168.1.104
</filesmatch>
#禁止解析PHP
<Directory /data/www/data/>
php_admin_flag engine off
<filesmatch "(.*)php">
Order deny,allow
Deny from all
Allow from 127.0.0.1
</filesmatch>
</Directory>
</VirtualHost>
编辑回复