[英]How to get a virtual host to work in OS X Lion?
I'm trying to set up a virtual host on my Mac OS X 10.7 Installation. 我正在尝试在Mac OS X 10.7安装上设置虚拟主机。 I'm using VirtualHostX to manage my /etc/hosts and httpd-vhosts.conf file.
我正在使用VirtualHostX来管理我的/ etc / hosts和httpd-vhosts.conf文件。 Currently, my httpd-vhosts.conf file looks like this:
目前,我的httpd-vhosts.conf文件如下所示:
NameVirtualHost *:80
<Directory "/Users/yuval/Sites/mysite/">
Allow From All
AllowOverride All
</Directory>
<VirtualHost *:80>
ServerName "mysite.dev"
DocumentRoot "/Users/yuval/Sites/mysite"
</VirtualHost>
and my /etc/hosts files has this in it: 我的/ etc / hosts文件中有这个:
# VHX START
127.0.0.1 mysite.dev
fe80::1%lo0 mysite.dev
# VHX STOP
I activated Web Sharing under System preferences, and I know apache is running. 我在系统首选项下激活了Web共享,我知道apache正在运行。 However, when I navigate to either 127.0.0.1 or to mysite.dev, I get the following:
但是,当我导航到127.0.0.1或mysite.dev时,我得到以下内容:
Forbidden
被禁止
You don't have permission to access / on this server.
您无权访问此服务器上的/。
My permissions on /Users/yuval/Sites/mysite are 755. Trying to change them to 777 didn't help either. 我在/ Users / yuval / Sites / mysite上的权限是755.尝试将它们更改为777也没有帮助。 Note that this is happening with any folder I choose -- I do not have an .htaccess file in /Users/yuval/Sites/mysite.
请注意,我选择的任何文件夹都会发生这种情况 - 我在/ Users / yuval / Sites / mysite中没有.htaccess文件。
Update : Checking the apache error, these are the logs that appear: 更新 :检查apache错误,这些是出现的日志:
[Fri Dec 09 17:59:27 2011] [error] [client 127.0.0.1] (13)Permission denied:
access to / denied
[Fri Dec 09 17:59:27 2011] [error] [client 127.0.0.1] (13)Permission denied:
access to /favicon.ico denied
It seems pretty obvious that the vhosts + hosts code is doing its job in actually determining that the address exists, but for some reason this isn't working. 很明显,vhosts + hosts代码在实际确定地址存在方面正在发挥作用,但由于某种原因,这不起作用。 Any ideas?
有任何想法吗?
Make sure an index.html
file is in the /Users/yuval/Sites/mysite/
directory. 确保
index.html
文件位于/Users/yuval/Sites/mysite/
目录中。
OR enable directory indexing: 或启用目录索引:
<Directory "/Users/yuval/Sites/mysite/">
Options +Indexes
Allow From All
AllowOverride All
</Directory>
You can also set the DirectoryIndex
option to look for default files other than index.html
: http://httpd.apache.org/docs/current/mod/mod_dir.html 您还可以设置
DirectoryIndex
选项以查找index.html
以外的默认文件: http : //httpd.apache.org/docs/current/mod/mod_dir.html
Edit 编辑
Saw your error message - this doesn't look like a directory index problem. 看到你的错误信息 - 这看起来不像目录索引问题。
Try chmod 755
on the /Users/yuval
directory as mentioned in this ServerFault answer: https://stackoverflow.com/a/1241319/212700 在
/Users/yuval
目录中尝试chmod 755
,如此ServerFault答案中所述: https : /Users/yuval
Also check for any .htaccess
files in the /Users/yuval/Sites/
directory as Apache will check those as well. 还要检查
/Users/yuval/Sites/
目录中的任何.htaccess
文件,因为Apache也会检查这些文件。
The only thing I had to do was re-point to my custom vhost directory (and restart apache.) 我唯一要做的就是重新指向我的自定义vhost目录(并重启apache。)
I tried to point to ~/Sites/vhosts instead of /Users/[Username]/Sites/vhosts where I keep all my .conf files, so there was a configuration error. 我试着指向〜/ Sites / vhosts而不是/ Users / [Username] / Sites / vhosts,我保存了所有的.conf文件,因此出现配置错误。 I was looking for the apache logs and learned from the apache docs about
httpd -S
which told me exactly where the configuration problems were. 我正在寻找apache日志,并从apache文档中了解到
httpd -S
,它告诉我确切的配置问题在哪里。
Lots of misinformation in blogs on the net so Im posting this here for apache noobs like me. 在网上的博客上有很多错误的信息,所以我在这里发布这个像我这样的apache noobs。
httpd -S
# fix the issues
sudo apachectl restart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.