如何使用apache httpd服务器启用多个域和/或子域

时间:2013-02-16 19:32:46

标签: apache vhosts multiple-domains

我正在尝试在我的环境开发中启用多个域,但是我没有按照我在下面尝试的方式取得成功,此时我错了?


我安装了httpd并将httpd.conf中的DocumentRoot更改为:

C:/Webserver/www


*我将Windows主机文件更改为(以斜体形式访问):
如果我切换到 127.0.0.1 api.rotadorock ,地址解析为www /但右边是www / rotadorock / api。

127.0.0.1                       localhost
127.0.0.1                       webserver
127.0.0.1/rotadorock/ecommerce  rotadorock
127.0.0.1/rotadorock/api        api.rotadorock
127.0.0.1/rotadorock/ecommerce  ecommerce.rotadorock
127.0.0.1/rotadorock/mobile     mobile.rotadorock
127.0.0.1/rotadorock/sistema    sistema.rotadorock
127.0.0.1/rotadorock/social     social.rotadorock

*更新(Windows主机文件)

我删除了上面提到的主机文件更改,因为@Volker Birk说没有必要。但即便如此,仍然无法按需访问(api.rotadorock /或localhost / api.rotadorock /并且应该指向 C:/ Webserver / www / rotadorock / api )。可能有什么不对?


最后更改了httpd-vhost.conf:

NameVirtualHost webserver:80

<Directory "C:/Webserver/www">
    Options All
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "c:/Webserver/www"
    ServerAlias localhost
    ErrorLog "logs/httpd-error.log"
    CustomLog "logs/httpd-access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerName webserver
    DocumentRoot "c:/Webserver/www"
    ServerAlias webserver
    ErrorLog "logs/httpd-error.log"
    CustomLog "logs/httpd-access.log" common
</VirtualHost>

<VirtualHost rotadorock:80>
    ServerName rotadorock
    DocumentRoot "c:/Webserver/www/rotadorock/ecommerce"
    ServerAlias rotadorock
    ErrorLog "logs/httpd-error.log"
    CustomLog "logs/httpd-access.log" common
</VirtualHost>

<VirtualHost api.rotadorock:80>
    ServerName api.rotadorock
    DocumentRoot "c:/Webserver/www/rotadorock/api"
    ServerAlias api.rotadorock
    ErrorLog "logs/httpd-error.log"
    CustomLog "logs/httpd-access.log" common
</VirtualHost>

<VirtualHost ecommerce.rotadorock:80>
    ServerName ecommerce.rotadorock
    DocumentRoot "c:/Webserver/www/rotadorock/ecommerce"
    ServerAlias ecommerce.rotadorock
    ErrorLog "logs/httpd-error.log"
    CustomLog "logs/httpd-access.log" common
</VirtualHost>

<VirtualHost mobile.rotadorock:80>
    ServerName mobile.rotadorock
    DocumentRoot "c:/Webserver/www/rotadorock/mobile"
    ServerAlias mobile.rotadorock
    ErrorLog "logs/httpd-error.log"
    CustomLog "logs/httpd-access.log" common
</VirtualHost>

<VirtualHost sistema.rotadorock:80>
    ServerName sistema.rotadorock
    DocumentRoot "c:/Webserver/www/rotadorock/sistema"
    ServerAlias sistema.rotadorock
    ErrorLog "logs/httpd-error.log"
    CustomLog "logs/httpd-access.log" common
</VirtualHost>

<VirtualHost social.rotadorock:80>
    ServerName social.rotadorock
    DocumentRoot "c:/Webserver/www/rotadorock/social"
    ServerAlias social.rotadorock
    ErrorLog "logs/httpd-error.log"
    CustomLog "logs/httpd-access.log" common
</VirtualHost>

2 个答案:

答案 0 :(得分:1)

您不需要hosts文件。查看文档:

http://httpd.apache.org/docs/2.2/en/vhosts/name-based.html

答案 1 :(得分:0)

终于解决了这个问题。我可以一起使用Windows主机文件和httpd-vhosts.conf httpd。

让我举一个例子,说明如何在本地访问多个子域。 在Windows主机上添加文件,对于每个域和子域,您需要这样的内容:

127.0.0.1    api.rotadorock #my subdomain
127.0.0.1    rotadorock #my domain

然后是httpd-vhosts apache httpd:

# Accessing the API
<VirtualHost 127.0.0.1>
    DocumentRoot "C:/Webserver/www/rotadorock/api"
    ServerName api.rotadorock
    ServerAlias ​​api.rotadorock

    <Directory "C:/Webserver/www/rotadorock/api">
        All Options Includes Indexes
    </ Directory>
</VirtualHost>

# Accessing the domain
<VirtualHost 127.0.0.1>
    DocumentRoot "C:/Webserver/www/rotadorock/"
    ServerName rotadorock
    ServerAlias ​​*.rotadorock

    <Directory "C:/Webserver/www/rotadorock/">
        All Options Includes Indexes
    </Directory>
</VirtualHost>

然后我可以在本地访问api.rotadorock /和rotadorock /。没有hosts文件,我试过各种方法。但只需要使用它。如果有人可以向我解释它应该怎么做,那么不需要使用主机我会很感激。