Feb27

apache中泛域名的简单案例

Author: 明分空分  Click: 6967   Date: 2010.02.27 @ 12:33:46 pm Category: 架构

目的:动态解析home.sst.cn的下级域名,username.home.sst.cn,实现基于虚拟域名(动态域名)的个人空间访问 。

实现步骤:

1.DNS的泛域名解析


@ IN SOA ns.sst.cn. zhao.sst.cn. (
20050817 ; Serial
3600 ; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
@  IN NS ns.sst.cn.

home IN A 123.123.123.123
*.home IN A 123.123.123.123

以上是在unix bind9下的设置,在windows server中的DNS设置与之同理,略。

2. web服务的设置

修改httpd.conf文件加入虚拟主机(如果需要同时供应多个web服务)
 


ServerAdmin zhao@home.sst.cn
DocumentRoot /somewhere/to/wwwhome
ServerName home.sst.cn
ServerAlias *.home.sst.cn
ErrorLog logs/home.sst.cn/error_log
CustomLog logs/home.sst.cn/access_log common


ServerName anotherweb.sst.cn
DocumentRoot /somewhere/to/anotherweb

为改变虚拟主机顺序,使提供泛域名的web服务为非中心主机(main host),加入此句:
ServerAlias *.home.sst.cn

  分析访问过程:
    用户输入[username].home.sst.cn
           |
           |
           |
           `-->apache分析主机头的值,不匹配任何一
               个虚拟主机名,则交送中心主机的目录
                        |
                        |
                        |
         接下来应该有两种方法处理:<--'
              |
              |
              ^ 
            '  `
            /    \
① 在home.sst.cn的根目录         ② 用mod_rewrite重写
设跳转文件,ASP代码举例:                URL指向[username]目录。
     |                 |
     |                 |
     |                 |

方法①纯代码方式,无用户目录。

方法②用mod_rewrite重写URL,指向用户目录。

 

在blog的主目录下建立.htaccess文件,内容为:



RewriteEngine On
#RewriteRule ^(.*)/home/(.*)$ $1.php?$2



TAG:   泛域名 module rewrite

    评论
    • 提交

    分类

    标签

    归档

    最新评论

    Abyss在00:04:28评论了
    Linux中ramdisk,tmpfs,ramfs的介绍与性能测试
    shallwe99在10:21:17评论了
    【原创】如何在微信小程序开发中正确的使用vant ui组件
    默一在09:04:53评论了
    Berkeley DB 由浅入深【转自架构师杨建】
    Memory在14:09:22评论了
    【原创】最佳PHP框架选择(phalcon,yaf,laravel,thinkphp,yii)
    leo在17:57:04评论了
    shell中使用while循环ssh的注意事项

    我看过的书

    链接

    其他

    访问本站种子 本站平均热度:8823 c° 本站链接数:1 个 本站标签数:464 个 本站被评论次数:94 次