如何在Apache 2.2上设置虚拟主机

时间:2009-05-05 14:22:52

标签: apache httpd.conf

有人能指导我如何使用Apache 2.2设置虚拟主机吗?这是我的情况:

我在我的笔记本电脑上运行Apache,我想要两个网站 - 一个在端口80上,一个在端口8089上。我想通过输入计算机的IP地址从我网络上的另一台计算机访问每个网站,例如{ {3}}和http://192.168.1.102。然而,当我输入第二个网址时,它会指示我访问在端口80上运行的网站。

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:4)

首先,您需要指示Apache监听您需要的端口:

Listen 80
Listen 8089

其次,您需要告诉它如何处理80和8089流量:

<VirtualHost *:80>
    DocumentRoot /website/site80
    ServerName internet.dev
</VirtualHost>

<VirtualHost *:8089>
    DocumentRoot /website/site8089
</VirtualHost>

第三,你需要“允许”Apache使用这些目录:

<Directory "C:/website/site80">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<Directory "C:/website/site8089">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

答案 1 :(得分:1)

只有2个虚拟主机定义如下,但具有不同的DocumentRoot:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.somecompany.com
    DocumentRoot "/docs/dummy-host.somecompany.com"
    ServerName dummy-host.somecompany.com
    ServerAlias www.dummy-host.somecompany.com
    ErrorLog "logs/dummy-host.somecompany.com-error.log"
    CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>

<VirtualHost *:8089>
    ServerAdmin webmaster@dummy-host.somecompany.com
    DocumentRoot "/docs/dummy-host.somecompany.com"
    ServerName dummy-host.somecompany.com
    ServerAlias www.dummy-host.somecompany.com
    ErrorLog "logs/dummy-host.somecompany.com-error.log"
    CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>