0

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


我安装了 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>
4

2 回答 2

1

您不需要主机文件。查看文档:

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

于 2013-02-16T20:05:13.763 回答
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/ 了。我尝试了所有没有主机文件的方法。但必须使用它。如果有人可以向我解释它应该如何做,那么它不需要使用主机,我将不胜感激。

于 2013-02-16T22:23:48.270 回答