LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1204|回复: 5

域名的问题!二级域名解析

[复制链接]
发表于 2003-5-29 21:52:28 | 显示全部楼层 |阅读模式
使用http://www.test.com/~user可以看到user在/home/user下的主页。
要实现http://user.test.com解析到http://www.test.com/~user该怎么做呢?
在哪里设置?
发表于 2003-5-29 22:26:13 | 显示全部楼层

回复: 域名的问题!




能说具体点你是怎么实现的吗???
发表于 2003-5-29 22:39:59 | 显示全部楼层

examples

虚拟主机配置例子

前提:
apache webserver with user_dir and rewrite modules;
www.test.com/user.test.com在dns服务器上都已经配置有效指向正确的ip;

配置文件:
httpd.conf或者vhosts.conf(看你的发布版不同会有所不同)

实际例子环境:
Mandrake9.1 apache2+php4

方法1(rewrite规则方法,即使你的user.test.com不和www.test.com在一个机器上用一个ip也好使,常用于动态域名重定向等,也用于dmz区域的简单负载均衡等)
... ...
NameVirtualHost 210.15.51.13:80
... ...
<VirtualHost 210.210.210.210>
ServerName user.test.com
ServerAlias www.user.test.com
Setenv VLOG /var/log/httpd
rewriteengine on
rewriterule ^/(.*)$ http://www.test.com/~user/$1 [P,L]
</VirtualHost>

方法2(常规作法,如果www.test.com和user.test.com是一个机器上,给出物理路径设置不同的DocumentRoot就可以了):
... ...
NameVirtualHost 210.15.51.13:80
... ...
<VirtualHost 210.210.210.210:80>
ServerName user.test.com
Setenv VLOG /var/log/httpd
DocumentRoot /home/user/public_html
</VirtualHost>
... ...

不只这些方法其实,还有更简单的,忘记了  太久没有仔细研究apache手册了。不过上述方法肯定有效就是了。
发表于 2005-5-2 16:07:45 | 显示全部楼层
使用http://www.test.com/~user可以看到user在/home/user下的主页。
要实现http://user.test.com解析到http://www.test.com/~user该怎么做呢?
在哪里设置?
我也有同样的问题,亟待解决~~~

情况和楼主差不多. 不过我想为多个用户做 rewrite.

例如:
(用户都已经建好了 public_html,用 http://www.test.com/~用户名 可以正常访问到各自的主页)

zhangsan 用户根目录 /home/zhangsan,想要转到 http://zhangsan.test.com
lisi 用户根目录 /home/lisi 想要转到 http://lisi.test.com
wangwu 用户根目录 /home/wangwu 想要转到 http://wangwu.test.com

请问,如何设置? 一定要设置 dns 解析 zhangsan.test.com 吗?
回复 支持 反对

使用道具 举报

发表于 2005-5-2 16:25:21 | 显示全部楼层
找到一段文字,也许有用.

Virtual User Hosts
Description:
Assume that you want to provide www.username.host.domain.com for the homepage of username via just DNS A records to the same machine and without any virtualhosts on this machine.
Solution:
For HTTP/1.0 requests there is no solution, but for HTTP/1.1 requests which contain a Host: HTTP header we can use the following ruleset to rewrite http://www.username.host.com/anypath internally to /home/username/anypath: RewriteEngine on
RewriteCond   %{HTTP_HOST}                 ^www\.[^.]+\.host\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^www\.([^.]+)\.host\.com(.*) /home/$1$2
回复 支持 反对

使用道具 举报

发表于 2005-5-3 11:18:44 | 显示全部楼层
范例一:
利用rewrite功能,在虚拟主机下加如下语句:
RewriteEngine on
RewriteCond %{HTTPS} !on [NC]
RewriteRule ^/erayt/ssl/(.*) https://www.test.com:443/erayt/ssl/$1 [L,R]
这样就可强制用https访问ssl目录下的所有网页.
范例二:
要完成的功能如下重定向:
将URL http://host/test.jps?id=1 重定向为 http://host/1.html
将URL http://host/conent.jsp?id=1&id2=3 重定向为 http://host/1_3.html

在每个虚拟主机的地方设置Rewrite参数

<VirtualHost *:80>
    ServerAdmin wweidong@sina.com
    DocumentRoot "I:/Job/Java"
    ServerName localhost
    RewriteEngine on
    RewriteRule /([0-9]+).html /test.jsp?id=$1 [PT]
    RewriteRule /([0-9]+)_([0-9]+).html /content.jsp?id=$1&id2=$2 [PT]
</VirtualHost>
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表