虚拟主机配置-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

虚拟主机配置

简介:

<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>



本文转自 linuxpp 51CTO博客,原文链接:http://blog.51cto.com/1439337369/1706683,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章
最新文章
相关文章