我在使用mac设置本地开发环境时遇到问题。
我有什么(补充):
/私人/ etc / hosts中:
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”第一个项目(第1页)可通过http://page1.dev.local访问,位于/ Users / user1 / Sites / page1
接下来的项目遵循相同的逻辑。
当我打开http://dev.local时,我看到了正确的页面,但是http://page1.dev.local我得到了相同的页面。
我当然总是重启Apache!
答案 0 :(得分: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>