目前这是我的httpd-vhosts.config
文件
NameVirtualHost *:80
<VirtualHost *:80>
VirtualDocumentRoot /Users/Gabri/Sites/%2/%1/build
</VirtualHost>
不过,我也希望能localhost
使用计算机 IP 在同一网络上查看它。所以我尝试了这个
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
VirtualDocumentRoot /Users/Gabri/Sites/
</VirtualHost>
<VirtualHost *:80>
VirtualDocumentRoot /Users/Gabri/Sites/%2/%1/build
</VirtualHost>
但它只指导localhost
我如何解决这个问题?
答案1
您的其他网站需要另一个服务器名称。并且您的 DNS 必须知道这一点!
<VirtualHost *:80>
VirtualDocumentRoot /Users/Gabri/Sites/%2/%1/build
ServerName Something
</VirtualHost>
答案2
我有同样的问题,但这样做可以解决这个问题,唯一的问题是,如果我在网站下创建一个新文件夹,我必须httpd-vhosts.conf
再次编辑文件。我希望有更简单的方法来做到这一点。
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot /Users/<username>/Sites/
ErrorLog "logs\errors.log"
</VirtualHost>
<VirtualHost *:80>
ServerAlias *.dev
VirtualDocumentRoot /Users/<username>/Sites/dev/%1/build
</VirtualHost>
<VirtualHost *:80>
ServerAlias *.wordpress
VirtualDocumentRoot /Users/<username>/Sites/wordpress/%1/public
</VirtualHost>
<VirtualHost *:80>
ServerAlias *.localhost
VirtualDocumentRoot /Users/<username>/Sites/localhost/%1/www
</VirtualHost>
答案3
您需要添加 ServerName 和 ServerAlias ,在您的情况下,您可能还需要一个通配符:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
VirtualDocumentRoot /Users/Gabri/Sites/
</VirtualHost>
<VirtualHost *:80>
ServerName default.localhost
ServerAlias default.localhost *
VirtualDocumentRoot /Users/Gabri/Sites/%2/%1/build
</VirtualHost>