ServerAlias 应用及测试 晴

jed , 2007-1-16 10:05 , 服务器技术 , 评论(0) , 阅读(4181) , Via 本站原创 | |


如果,想实现多个域名访问同一个网站时,可以使用ServerAlias来实现:

前提条件:
已在域名服务提供商处或自己管理的DNS服务器上,将多个域名或A记录(如:test.com 、www.test.com 、pub.test.com )指向同一个公网IP(如:166.166.166.166)

此例中,Apache中涉及到的相关选项说明:
NameVirtualHost *           (设定虚拟主机的ip)
           (开头设定虚拟主机的ip)
ServerAdmin admin@domain.com   (设定虚拟主机的管理者信箱,不用和预设的网站管理者相同)
DocumentRoot /yourdir        (指定虚拟主机的网站主目录)
ServerName domain.com        (设定虚拟主机的名称,指定设定虚拟主机的UR)
ServerAlias www.domain.com     (设定虚拟主机的別名,例: WWW )
ErrorLog logs/?? ??          (虚拟主机发生错误时要记录在哪个目录,可不设.)
TransferLog logs/??         (虚拟主机存取记载要存放的个目录,可不设.)
           (结束,要设第二组虚拟主机在从开头开始设)


在Apache中的配置:
NameVirtualHost 166.166.166.166


ServerAdmin admin@test.com
DocumentRoot /your/web/file/dir
ServerName test.com
ServerAlias www.test.com
ServerAlias pub.test.com
ErrorLog logs/test.com_error_log
TransferLog logs/test.com_transfer_log



如果没有条件设置域名,在windows环境下可以做如下测试:
修改hosts主机文件,用记事本打开:
C:\WINNT\system32\drivers\etc\hosts

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1       localhost


加入:
166.166.166.166        test.com
166.166.166.166        www.test.com
166.166.166.166        pub.test.com

在CMD下测试PING这三个域名,如果通,就可以测试apache了。
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]