升级到Yosemite后,Apache配置出现问题

7

昨天我升级到Yosemite,现在我的本地网络开发配置不再起作用了。

我设法在/Users/user/public_html下设置了一个用户目录,并且可以通过localhost/~user/websitename访问所有网站。虽然没有什么特别的,但我花了一些时间进行配置。

查看apache目录时,我发现许多文件被替换了,所以我备份了它们。我试着把带有我的设置的文件放回去,但仍然不起作用。也许我忘记了某个文件。

这是httpd-userdir.conf:

# Settings for user home directories
#
# Required module: mod_userdir

#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.  Note that you must also set
# the default access control for these directories, as in the example below.
#
UserDir public_html

#
# Users might not be in /Users/*/Sites, so use user-specific config files.
#
Include /private/etc/apache2/users/*.conf
<IfModule bonjour_module>
       RegisterUserSite customized-users
</IfModule>

<Directory "/Users/*/public_html/">
    AllowOverride FileInfo AuthConfig Limit Indexes
        Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
        Order allow,deny
        Allow from all
</Directory>

然后在http.conf文件中,我启用了一些模块:

Include /private/etc/apache2/extra/httpd-userdir.conf
LoadModule userdir_module libexec/apache2/mod_userdir.so

and this:

DocumentRoot "/Users/user/public_html"

Directory "/Users/user/public_html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks MultiViews

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride all

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>

如果我尝试访问localhost,它会显示消息“ It works!”。但如果我访问localhost/user,页面就无法加载,如果我尝试访问其中一个网站也是一样的。我错过了什么文件吗?在apache日志中甚至没有显示任何错误。

2
优胜美地升级了Apache从2.2到2.4。配置已更改。您启用了mod_userdir模块吗?此外,您还需要更改“Order”和“Allow”指令。您可能需要查看升级指南http://httpd.apache.org/docs/2.4/upgrading.html。 - Sean Coyne
1
将来的读者可能希望以正确的方式开始在Mac OS X Yosemite上安装Apache、PHP和MySQL。可以参考此链接:http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/ - Jason McCreary
此外,请阅读此链接:https://discussions.apple.com/thread/6602475#26885389 - luisnicg
2个回答

18

OS X 10.10 Yosemite自带的Apache版本是2.4,而不是Mavericks中的2.2。
配置方面的主要区别在于您需要替换...

Order allow,deny
Allow from all
...使用...
Require all granted

请参阅 Apache 文档手册中的 从 2.2 升级到 2.4,获取更多详细信息。

更新:
请注意,在升级 OS X 后,您通常会发现旧的配置文件被备份为 Yosemite 创建的新文件的副本。它们标记为例如 httpd.conf.pre-update 和/或 httpd.conf~previous,可以在与新配置相同的路径中找到(例如,在 /private/etc/apache2 中)。


取消在httpd.conf中引用userdir的两行注释,取消在httpd-userdir.conf中的Include注释,并在Guest.conf中进行上述更改,最终为我修复了~Guest网站。谢谢! - lionello
1
@Michael,如果你进行了Apache 2.4的全新安装,你将不会找到任何Order或Allow行。但是,如果你接管了来自Apache 2.2的现有配置,你应该在httpd.conf(例如,在DocumentRoot指令行之后)以及httpd-vhosts.conf(如果你使用虚拟主机)中找到它们。 - Jpsy
@Jpsy 我明白,我想说的是我已经在所有的配置文件中使用了grep命令(它们原本是2.2版本,但现在由于Yosemite升级变成了2.2和2.4混合),但我在任何一个版本中都没有看到这些字符串。另外,我刚刚去再次检查了一下,显然Yosemite也破坏了我的sshd设置,所以我目前无法远程登录。 - Michael
@Michael 你知道 Yosemite 不仅会重写你的配置文件,还会保留旧版本作为备份吗?它们被标记为 httpd.conf.pre-update 或者 httpd.conf~previous,可以在与新配置文件相同的路径下找到(例如 /private/etc/apache2)。我已经在我的回答中添加了这些信息。 - Jpsy
@Jpsy 谢谢,是的我知道那个。但在我的情况下问题似乎比你发给我的链接中所说的仅仅将Order/Allow更改为Require要复杂一些。 - Michael

1

在尝试修复此问题6个小时后,我终于成功了。我编辑了httpd.conf、httpd-userdir.conf、 httpd-vhosts.conf等文件,但没有任何效果。最终让我成功的方法是编辑位于/Library/Server/Web/Config/apache2/的httpd_server_app.conf文件,并添加以下内容(对于每个站点):

<Directory />
 Options +FollowSymLinks
 AllowOverride All
 Order deny,allow
 Deny from all
</Directory>

<Directory "/Library/Server/Web/Data/Sites/Default/">
 Options +Indexes +FollowSymLinks +MultiViews
 AllowOverride All
 Order allow,deny
 Allow from all
</Directory>

<Directory "/Library/Server/Web/Data/Sites/[OTHER SITE DIRECTORY]/">
 Options +Indexes +FollowSymLinks +MultiViews
 AllowOverride All
 Order allow,deny
 Allow from all
</Directory>

请确保使用TextEdit编辑此文件时撤消斜引号的自动插入,否则将收到Unicode错误消息。
希望这可以帮到你!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接