Linux下Apache绑定多个域名的方法

1、将#ServerName www.example.com:80修改成ServerName 94.249.188.58:80,注意别忘记了将句首的#去掉;

2、将#NameVirtualHost *:80修改成NameVirtualHost 94.249.188.58:80,注意别忘记了将句首的#去掉;

3、在文件最后面有虚拟主机格式:

# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#
#*IP访问/var/www/html/dir目录

ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/dir
ServerName 127.0.0.1
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common

#*mudbest.com与www.mudbest.com访问/var/www/html/dir1目录

ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/dir1
ServerName mudbest.com
ServerAlias www.mudbest.com
ErrorLog logs/mudbest.com-error_log
CustomLog logs/mudbest.com-access_log common

#*mudbest.com与www.mudbest.com访问/var/www/html/dir2目录

ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/dir2
ServerName mudbest.com
ServerAlias www.mudbest.com
ErrorLog logs/mudbest.com-error_log
CustomLog logs/mudbest.com-access_log common

附:如果想开其他端口,请按照如下操作(以8080端口为例):

1、打开http.conf,查找Listen 80,在下面一行添加Listen 8080;

2、在文件末尾添加如下代码:

ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/dir3
ServerName mudbest.com
ServerAlias www.mudbest.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common

这样就将www.mudbest.com:8080绑定到/var/www/html/dir3目录了。

Apache
Apache的“虚拟主机”,能够很好的支持多域名,绑定同一IP的某端口。
具体如下:
我要添加2个域名
http://demo1.mudbest.com 指向 D:\web1\
http://demo2.mudbest.com 指向 D:\web2\
修改httpd.conf
在文件最后找到

#NameVirtualHost
*:80
#
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#

仿照上面的例子,在此之后,添加

NameVirtualHost
*:80

ServerName demo1.mudbest.com
DocumentRoot
"D:/web1/"

ServerName demo2.mudbest.com
DocumentRoot
"D:/web2/"

Leave a Reply

(will not be published)