3

我在 Mac 上设置本地开发环境时遇到问题。

我有什么(添加):

/私人/等/主机:

127.0.0.1       dev.local
127.0.0.1       page1.dev.local

/Applications/MAMP/conf/apache/httpd.conf:

NameVirtualHost *

<VirtualHost dev.local:8888>
    ServerName dev.local
    DocumentRoot /Users/user1/Sites/
    <Directory /Users/user1/Sites/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

<VirtualHost page1.dev.local:8888>
    ServerName page1.dev.local
    DocumentRoot /Users/user1/Sites/page1/
    <Directory /Users/user1/Sites/page1/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

基本上我想通过http://dev.local和 /Users/user1/Sites 物理访问“root”

第一个项目(page1)可通过http://page1.dev.local访问,位于 /Users/user1/Sites/page1

下一个项目遵循相同的逻辑。

当我打开http://dev.local 时,我看到了正确的页面,但是使用http://page1.dev.local我得到了相同的页面。

我当然总是重启 Apache!

4

1 回答 1

1

我找到了一个可行的解决方案:我必须在之后插入一个ServerAlias并添加一个星号VirtualHost

NameVirtualHost *

<VirtualHost *:8888>
    ServerName dev.local
    ServerAlias dev.local
    DocumentRoot /Users/user1/Sites/
    <Directory /Users/user1/Sites/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:8888>
    ServerName page1.dev.local
    ServerAlias page1.dev.local
    DocumentRoot /Users/user1/Sites/page1/
    <Directory /Users/user1/Sites/page1/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>
于 2012-07-09T07:52:55.067 回答