【问题标题】:Broken Apache configuration after upgrading to Yosemite升级到优胜美地后 Apache 配置损坏
【发布时间】:2014-12-16 13:28:05
【问题描述】:

昨天我升级到 Yosemite,现在我的本地 Web 开发配置不再工作了。

我设法在/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

还有这个:

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,它会显示消息“它有效!”。如果我去localhost/user 根本不会加载,如果我尝试访问其中一个网站也是一样的。

我错过了任何文件吗?在 apache 日志中它甚至没有显示任何错误。

【问题讨论】:

标签: php macos apache osx-yosemite


【解决方案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 错误消息。

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    OS X 10.10 Yosemite 随附 Apache 2.4 而不是 Mavericks 中的 Apache 2.2。
    配置的主要区别是你必须更换...

    Order allow,deny
    Allow from all
    

    ...与...

    Require all granted
    

    有关详细信息,请参阅 Apache 文档的手册 Upgrading to 2.4 from 2.2

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

    【讨论】:

    • 取消注释 httpd.conf 中引用 userdir 的两行,取消注释 httpd-userdir.conf 中的 Include 并在 Guest.conf 中进行上述更改最终为我修复了 ~Guest 站点。谢谢!
    • @Michael 如果您全新安装 Apache 2.4,您将找不到任何 Order 或 Allow 行。但是,如果您从 Apache 2.2 接管现有配置,您绝对应该在 httpd.conf(例如,遵循 DocumentRoot 指令行)以及 httpd-vhosts.conf(如果您使用虚拟主机)中找到它们。
    • @Jpsy 我明白,我的意思是我已经 grepped 我的所有配置文件(这些文件是 2.2,但由于优胜美地升级,现在是 2.2 和 2.4 的混合),我没有在任何一个中都看不到这些字符串。此外,我刚刚仔细检查了这一点,显然 Yosemite 也破坏了我的 sshd 设置,所以我目前无法远程登录。
    • @Michael 您知道优胜美地不仅会重写您的配置文件,还会保留旧版本作为备份?它们被标记为例如httpd.conf.pre-update 和/或 httpd.conf~previous 可以在与新配置相同的路径中找到(例如 /private/etc /apache2)。我已将此信息添加到我的答案中。
    • @Jpsy 谢谢,是的,我知道这一点。就我而言,问题在于它似乎比简单地将 Order/Allow 更改为 Require(根据您发送给我的链接)要复杂一些。
    猜你喜欢
    • 2015-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    • 1970-01-01
    • 2015-03-13
    相关资源
    最近更新 更多