【问题标题】:Broken Apache Virtual Hosts after Yosemite upgrade优胜美地升级后损坏的 Apache 虚拟主机
【发布时间】:2015-01-19 09:48:27
【问题描述】:

我最近升级到 MAC OS X Yosemite,但我的虚拟主机的 apache 配置无法正常工作。我按照@raoulsson (https://superuser.com/questions/827937/apache-problems-after-upgrading-to-yosemite) 的建议升级了 php:

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6

并且还编辑了/etc/apache2/extra/httpd-vhosts.conf:

<VirtualHost *:80>
 ServerName test.local
 DocumentRoot "/Users/my-name/www/test"

 <Directory "/Users/my-name/www/test>
     AllowOverride All
     #Order allow,deny
     #Allow from all
    Require all granted

    RewriteEngine on

    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Rewrite everything else to index.html to allow html5 state links
    RewriteRule ^ index.html [L]
 </Directory>

 <IfModule dir_module>
    DirectoryIndex index.html
 </IfModule>

 <Files ".ht*">
    Order deny,allow
    Deny from all
 </Files>
</VirtualHost>

现在导航到我的一个虚拟主机 (http://test.local) 会给我消息“它可以工作”,而不是显示我的网站。有人知道我缺少什么吗?

编辑: 所以事实证明问题出在 /etc/apache2/httpd.conf 中。我必须重新启用虚拟主机才能使其正常工作。由于我在上面的虚拟主机中使用了重写,我还必须加载重写引擎。

LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

不确定 alias_module 是否必要,但我的配置现在可以正常工作,所以我将保留它。

【问题讨论】:

    标签: php apache osx-yosemite


    【解决方案1】:

    首先,您需要删除某些行中的“#”。尤其是默认情况下不导入 vhost.conf 文件。

    喜欢:

    #LoadModule php5_module libexec/apache2/libphp5.so
    #LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
    #Include /private/etc/apache2/extra/httpd-vhosts.conf
    

    LoadModule php5_module libexec/apache2/libphp5.so
    LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
    Include /private/etc/apache2/extra/httpd-vhosts.conf
    

    并在其他部分添加一些“#”

    <Directory />
         AllowOverride none
         Require all denied
    </Directory>
    

    <Directory />
         #AllowOverride none
         #Require all denied
    </Directory>
    

    根据http://mallinson.ca/osx-web-development/

    【讨论】:

    • 谢谢,你帮我省了一个小时的时间 :)
    【解决方案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)。

    【讨论】:

    • 感谢关于更新前的说明,不知道 :)
    猜你喜欢
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 2017-03-04
    • 2015-03-13
    相关资源
    最近更新 更多