vhost配置
<VirtualHost *:80>
DocumentRoot "/tmp/tmp"
ServerName tmp.com
<Directory /tmp/tmp/>
Order allow,deny
Deny from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/www"
ServerName www.1.com
ServerAlias www.a.com www.b.com
ServerAlias www.c.com
# 用户认证
# <Directory /data/www>
# AllowOverride AuthConfig
# AuthName "alksdjflkasjdf"
# 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.1.com$
RewriteRule ^/(.*)$ http://www.1.com/$1 [R=301,L]
RewriteRule ^/(.*)\.png$ /static/image/common/fav.gif [R=302]
#RewriteRule ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=viewthread&tid=$1&extra=page%3D$2
RewriteRule ^/topic-(.+)\.html$ /portal.php?mod=topic&topic=$1&%1
RewriteRule ^/article-([0-9]+)-([0-9]+)\.html$ /portal.php?mod=view&aid=$1&page=$2&%1
RewriteRule ^/forum-(\w+)-([0-9]+)\.html$ /forum.php?mod=forumdisplay&fid=$1&page=$2&%1
RewriteRule ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
RewriteRule ^/group-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=group&fid=$1&page=$2&%1
RewriteRule ^/space-(username|uid)-(.+)\.html$ /home.php?mod=space&$1=$2&%1
RewriteRule ^/blog-([0-9]+)-([0-9]+)\.html$ /home.php?mod=space&uid=$1&do=blog&id=$2&%1
RewriteRule ^/archiver/(fid|tid)-([0-9]+)\.html$ /archiver/index.php?action=$1&value=$2&%1
RewriteRule ^/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ /plugin.php?id=$1:$2&%1
RewriteCond %{HTTP_USER_AGENT} ^.*Firefox/4.0* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*curl* [NC]
RewriteRule .* - [F]
</IfModule>
# 配置日志
ErrorLog "/usr/local/apache2/logs/dummy-host.example.com-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>
<Ifmodule mod_headers.c>
<filesmatch "\.(html|htm|txt)$">
header set cache-control "max-age=3600"
</filesmatch>
<filesmatch "\.(css|js|swf)$">
header set cache-control "max-age=604800"
</filesmatch>
<filesmatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">
header set cache-control "max-age=29030400"
</filesmatch>
</ifmodule>
# 配置防盗链
<Directory /data/www/>
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>
</Directory>
# 访问控制
#<Directory /data/www/admin>
#<filesmatch ".*">
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
#</filesmatch>
#</Directory>
#<Directory /data/www>
#<Filesmatch "^admin.php(.*)$">
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
#</Filesmatch>
#</Directory>
<Directory /data/www/uc_server>
php_admin_flag engine off
<filesmatch "(.*)php">
Order deny,allow
Deny from all
</filesmatch>
</Directory>
</VirtualHost>
######################################
#虚拟主机配置
DocumentRoot "/data/www"
ServerName www.dis1.com
ServerAlias www.dis2.com
ErrorLog "logs/dis1.com-error_log"
#访问日志不记录指定类型的文件
SetEnvIf Request_URI ".*\.jpg$" image-request
SetEnvIf Request_URI ".*\.gif$" 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/dis1.com-access_log_%Y%m%d 86400" combined Env=!image-request
#域名跳转
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.dis2.com$
RewriteRule ^/(.*)$ http://www.dis1.com/$1 [R=301,L]
#通过rewrite模块限制指定的User_Agent访问
RewriteCond %{HTTP_USER_AGENT} ^.*sogou.* [NC]
RewriteRule .* - [F]
#通过rewrite模块限制对/data/www/tmp目录的访问
RewriteCond %{REQUEST_URI} ^.*/tmp/.* [NC]
RewriteRule .* - [F]
#指定文件静态缓存
ExpiresActive on
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpg "acccess plus 24 houre"
ExpiresByType image/png "access plus 24 hours"
ExpiresByType text/css "now plus 2 hours"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
#防盗链
SetEnvIfNoCase Referer ".*\.dis1.com" local_ref
Order Allow,Deny
Allow from env=local_ref
#Apache访问控制
AllowOverride None
Options None
Order Allow,Deny
Allow from all
Deny from 127.0.0.1
#限制某些页面只能从固定ip访问
Order Deny,Allow
Deny from all
Allow from 192.168.31.184
#禁止解析并下载php文件,假如.php文件放在/data/www/data下
php_admin_flag engine off
Order Deny,Allow
Deny from all
#指定目录用户认证
AllowOverride AuthConfig
AuthName "Need to be allowed!"
AuthType basic
AuthUserFile /data/.htpasswd
Require valid-user
本文出自 “实用Linux知识技能分享” 博客,请务必保留此出处http://superleedo.blog.51cto.com/12164670/1890076
原文地址:http://superleedo.blog.51cto.com/12164670/1890076