【发布时间】:2015-10-16 03:39:34
【问题描述】:
我在家用计算机上使用具有 2 个本地域的 Apache VirtualHosts 进行开发和测试。
• d4damage.local (personal websites)
• company.local (work stuff on external drive)
它在我的网络上运行良好。但是,我还需要通过IP192.168.1.60选择性访问d4damage.local(我的电脑固定到这个IP)
原因是我的 PS3 无法解析d4damage.local,但它可以通过 IP。 (使用d4damage.local我所有其他的wi-fi设备都很好)
看来我可以将d4damage.local 设置为使用IP 或名称,但不能同时使用两者。 (403 禁止)注释行显示替代方案。
httpd-vhosts.conf
#NameVirtualHost 192.168.1.60:80
#<VirtualHost 192.168.1.60:80>
<VirtualHost *:80>
ServerAdmin admin@d4damage.local
DocumentRoot "/Users/paul/Sites"
ServerName d4damage.local
ErrorLog "/private/var/log/apache2/d4damage.local-error_log"
CustomLog "/private/var/log/apache2/d4damage.local-access_log" common
</VirtualHost>
httpd.conf
ServerName d4damage.local
...
DocumentRoot "/Users/paul/Sites"
<Directory "/Users/paul/Sites">
主机
127.0.0.1 localhost
192.168.1.60 company.local d4damage.local
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
以上文件涉及我希望在我的计算机上使用的主域,company.local 一个是附加的,我不需要通过 IP 访问它。
希望您能提供帮助!谢谢。
【问题讨论】:
-
注意:
ServerName d4damage.local在 http.conf 和 VirtualHosts 关闭 - 我可以通过任何设备上的 IP 和名称访问。但是通过激活 VirtualHosts 我失去了通过 IP 访问的能力。 -
我没有测试过你的情况,但是当你使用 VirtualHosts 时你不应该评论
NameVirtualHost行。您可以使用NameVirtualHost *:80。另外,当您使用 VirtualHost 时,我认为您不需要 httpd.conf 中的ServerName。 -
感谢您的意见。我都试过了,不幸的是,两者都没有区别。
标签: apache2 virtualhost