macos 如何让虚拟主机在 OS X Lion 中工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8453662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get a virtual host to work in OS X Lion?
提问by Yuval Karmi
I'm trying to set up a virtual host on my Mac OS X 10.7 Installation. I'm using VirtualHostX to manage my /etc/hosts and httpd-vhosts.conf file. Currently, my httpd-vhosts.conf file looks like this:
我正在尝试在我的 Mac OS X 10.7 安装上设置一个虚拟主机。我正在使用 VirtualHostX 来管理我的 /etc/hosts 和 httpd-vhosts.conf 文件。目前,我的 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. However, when I navigate to either 127.0.0.1 or to mysite.dev, I get the following:
我在系统首选项下激活了网络共享,我知道 apache 正在运行。但是,当我导航到 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. 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 的权限是 755。尝试将它们更改为 777 也无济于事。请注意,我选择的任何文件夹都会发生这种情况——我在 /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. Any ideas?
很明显,vhosts + hosts 代码在实际确定地址存在方面正在发挥作用,但由于某种原因,这不起作用。有任何想法吗?
采纳答案by leepowers
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
尝试chmod 755
使用/Users/yuval
此 ServerFault 答案中提到的目录:https://stackoverflow.com/a/1241319/212700
Also check for any .htaccess
files in the /Users/yuval/Sites/
directory as Apache will check those as well.
还要检查.htaccess
目录中的任何文件,/Users/yuval/Sites/
因为 Apache 也会检查这些文件。
回答by Shanimal
The only thing I had to do was re-point to my custom vhost directory (and restart apache.)
我唯一要做的就是重新指向我的自定义虚拟主机目录(并重新启动 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. 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.
我试图指向 ~/Sites/vhosts 而不是 /Users/[Username]/Sites/vhosts 我保存我所有的 .conf 文件,所以有一个配置错误。我正在寻找 apache 日志并从 apache docs 中了解到httpd -S
它告诉我配置问题的确切位置。
Lots of misinformation in blogs on the net so Im posting this here for apache noobs like me.
网络上的博客中有很多错误信息,所以我在此处为像我这样的 apache 新手发布此信息。
httpd -S
# fix the issues
sudo apachectl restart