1. 程式人生 > >關於用兩個網址訪問一個服務器上不同站點

關於用兩個網址訪問一個服務器上不同站點

com dex 監聽 listen 解決方法 rtu one 不同 mage

技術分享

要求就是通過http://www.xiaolu.com訪問在位置f:myblog下的文件index.html;通過http://www.xiaolu1.com訪問在位置f:myblog1下的index.htm文件

解決方法一、

1、配置httpd.conf文件,啟用httpd-vhosts.conf

即,將#Include conf/extra/httpd-vhosts.conf前面的#去掉

2、配置httpd-vhosts.conf(位置conf/extra/httpd-vhosts.conf)

<VirturalHost 127.0.0.1:80>

DocumentRoot "f:/myblog"

DirectoryIndex index.html inde.htm index.php

<Directory />

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

<VirturalHost 127.0.0.1:81>

DocumentRoot "f:/myblog1"

DirectoryIndex index.html inde.htm index.php

<Directory />

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

3、在httpd.conf文件中讓Apache監聽81端口

Listen 81

4、在hosts文件中添加新的IP和對應域名設置

127.0.0.1 www.xiaolu.com

127.0.0.1 www.xiaolu1.com

5、訪問時候

http://www.xiaolu1.com:81

解決方法二、

1、配置httpd.conf文件,啟用httpd-vhosts.conf

即,將#Include conf/extra/httpd-vhosts.conf前面的#去掉

2、配置httpd-vhosts.conf

<VirturalHost *:80>

DocumentRoot "f:/myblog"

#這裏指定域名

ServerName www.xiaolu.com

DirectoryIndex index.html inde.htm index.php

<Directory />

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

<VirturalHost *:80>

DocumentRoot "f:/myblog1"

ServerName www.xiaolu.com

DirectoryIndex index.html inde.htm index.php

<Directory />

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

3、在httpd.conf文件中設置訪問權限

<Directory />
#AllowOverride none
#Require all denied
Options FollowSymLinks
AllowOverride None
Order deny,allow
# Deny from all
Allow from all
</Directory>

4、在hosts文件中添加新的IP和對應域名設置

127.0.0.1 www.xiaolu.com

127.0.0.1 www.xiaolu1.com

5、訪問時候

http://www.xiaolu1.com(可以正常訪問不用帶:81)

關於用兩個網址訪問一個服務器上不同站點