在 OSX 10.7 (Lion) 上设置 VirtualHost

在 OSX 10.7 (Lion) 上设置 VirtualHost

我终于切换到 Lion,但在设置 Apache VirtualHost 时遇到了问题。这是我目前所做的,但我不知道为什么它不起作用。

1)在 /etc/apache2/httpd.conf 中我取消了此行的注释:

Include /private/etc/apache2/extra/httpd-vhosts.conf

2)在httpd-vhosts.conf中我输入了以下内容:

NameVirtualHost *:80    

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "/Library/WebServer/Documents"
</VirtualHost>

<VirtualHost *:80>
    ServerName work.local
    DocumentRoot "/Users/me/Work"
    <Directory /Users/me/Work>
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

3)然后我在〜/ Work中创建了一个index.html

4)最后我sudo apachectl restart(我也从系统偏好设置中的共享重新启动它)

...但是当我去 work.local 时它找不到它,也无法 ping 它。

$ ping work.local
ping: cannot resolve work.local: Unknown host


$ apachectl -S
httpd: Could not reliably determine the server's fully qualified domain name, using me-iMac.local for ServerName
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server localhost (/etc/apache2/other/httpd-vhosts.conf:17)
         port 80 namevhost localhost (/etc/apache2/other/httpd-vhosts.conf:17)
Syntax OK

答案1

$ ping 工作.本地

ping:无法解析 work.local:未知主机

系统没有work.local的IP

在 /etc/hosts 中添加 work.local 作为主机名

请参阅 evt. 有关 lion 上的 dsn http://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/

相关内容