在El Capitan

时间:2016-06-02 10:48:21

标签: macos apache virtualhost httpd.conf osx-elcapitan

我所做的是:

将此添加到httpd-vhosts.conf:

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents/site1"
    ServerName site1.loc
    ServerAlias www.site1.loc
    ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents/site2"
    ServerName site2.loc
    ServerAlias www.site2.loc
    ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>

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

在hosts文件中,我添加了这个:

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
127.0.0.1 site1.localhost
127.0.0.1 site2.localhost

最后在httpd.conf中我取消注释了这一行:

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

在此之后我尝试运行类似的东西后重新启动了apache:

http://site1/index.html

http://site2我收到一条错误,上面写着:

  

无法访问此网站

我遗失了一些非常明显的东西?我在Windows上做了很长时间,所以我想我犯了一些愚蠢的错误。我也得到了:

  

您无权访问此服务器上的/。

当我尝试联系localhost时。

1 个答案:

答案 0 :(得分:0)

实际上,在我改变了这些之后它才起作用:

127.0.0.1 site1.localhost
127.0.0.1 site2.localhost

到此:

127.0.0.1 site1.loc
127.0.0.1 site2.loc