如何让虚拟主机在 OS X Lion 中工作?

发布于 2024-12-20 23:46:45 字数 1164 浏览 4 评论 0原文

我正在尝试在 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>

我的 /etc/hosts 文件中包含以下内容:

# VHX START
127.0.0.1 mysite.dev
fe80::1%lo0 mysite.dev
# VHX STOP

我在系统首选项下激活了 Web 共享,并且我知道 apache 正在运行。但是,当我导航到 127.0.0.1 或 mysite.dev 时,我得到以下信息:

禁止

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

我对 /Users/yuval/Sites/mysite 的权限是 755。尝试将它们更改为 777 也没有帮助。请注意,我选择的任何文件夹都会发生这种情况 - 我在 /Users/yuval/Sites/mysite 中没有 .htaccess 文件。

更新:检查 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

看起来很明显,vhosts + 主机代码正在实际确定地址存在,但由于某种原因,这不是'工作。有什么想法吗?

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:

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:

# 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:

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.

Update: Checking the apache error, these are the logs that appear:

[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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

知你几分 2024-12-27 23:46:45

确保 index.html 文件位于 /Users/yuval/Sites/mysite/ 目录中。

或者启用目录索引:

<Directory "/Users/yuval/Sites/mysite/">
  Options +Indexes
  Allow From All
  AllowOverride All
</Directory>

您还可以设置 DirectoryIndex 选项来查找除 index.html 之外的默认文件: org/docs/current/mod/mod_dir.html" rel="nofollow noreferrer">http://httpd.apache.org/docs/current/mod/mod_dir.html

编辑

看到您的错误消息 - 这看起来不像目录索引问题。

尝试在 /Users/yuval 目录上使用 chmod 755,如 ServerFault 答案中所述:https://stackoverflow.com/a/1241319/212700

同时检查以下目录中是否有任何 .htaccess 文件/Users/yuval/Sites/ 目录,因为 Apache 也会检查这些目录。

Make sure an index.html file is in the /Users/yuval/Sites/mysite/ directory.

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

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

Also check for any .htaccess files in the /Users/yuval/Sites/ directory as Apache will check those as well.

浅唱ヾ落雨殇 2024-12-27 23:46:45

我唯一要做的就是重新指向我的自定义虚拟主机目录(并重新启动 apache)。

我尝试指向 ~/Sites/vhosts 而不是 /Users/[用户名]/Sites/vhosts 我保存所有 . conf 文件,因此存在配置错误。我正在寻找 apache 日志,并从 apache 文档中了解到有关 httpd -S 的信息,它准确地告诉我配置问题出在哪里。

网络上的博客中有很多错误信息,所以我在这里为像我这样的 apache 新手发布此信息。

httpd -S
# fix the issues
sudo apachectl restart

The only thing I had to do was re-point to my custom vhost directory (and restart 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.

Lots of misinformation in blogs on the net so Im posting this here for apache noobs like me.

httpd -S
# fix the issues
sudo apachectl restart
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文