Feb27

apache中泛域名的简单案例

Author: 明分空分  Click: 1157   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

    评论
    • 提交

    分类

    标签

    归档

    最新评论

    王爷在21:32:04评论了
    【原创】获取jQuery中Ajax函数的返回值的方法
    Funny在10:22:51评论了
    shell数组使用方法小记
    kevinems在11:30:08评论了
    【原创】使用gitosis和tortoisegit打造自己的git服务
    candy在13:11:40评论了
    【原创】beautifulsoup解析中文网页乱码解决
    thenbsp.com在16:17:48评论了
    中国邮政EMS就是一坨屎

    我看过的书

    链接

    其他

    访问本站种子 本站平均热度:1218 c° 本站链接数:55 个 本站标签数:250 个 本站被评论次数:33 次