【发布时间】:2015-02-04 19:31:39
【问题描述】:
我有一个站点,Ruby on Rails 通过 Phusion Passenger 在根目录中运行。一些 Apache Alias 指令服务于静态 HTML 目录。
如果您从其中一个静态目录请求文件的确切 URL,Apache 会按预期返回它。但是,在某些情况下,我没有得到预期的行为。考虑别名 Alias /functional /path/to/functional,其中 functional 目录包含 index.php 和 hello.jpg。
- https://example.com/functional/hello.jpg 的请求会按预期返回 JPEG 文件。
- https://example.com/functional/index.php 的请求会运行 PHP 脚本并按预期打印生成的 HTML 文档。
- https://example.com/functional/ 的请求导致 Rails 堆栈中出现 404。
- 对https://example.com/functional 的请求(没有尾部斜杠)也会导致Rails 堆栈中出现404。理想情况下,此 URL 应返回 301,将用户重定向到 http://example.com/functional/
如果我将 index.html 文件添加到 functional 目录中(除了已经存在的 index.php 之外),路径 #3 和 #4 按预期返回该文件。
这是我的乘客 Apache 配置文件中的相关部分:
LoadModule passenger_module /path/to/mod_passenger.so
LoadModule ssl_module modules/mod_ssl.so
<IfModule mod_passenger.c>
# ... passenger setup stuff omitted ...
Listen 443
<VirtualHost *:443>
ServerName ...
DocumentRoot /path/to/rails/public
PassengerRuby /path/to/ruby
<Directory /path/to/rails/public>
Allow from all
Options -MultiViews
</Directory>
# ... ssl setup omitted ...
</VirtualHost>
</IfModule>
对于静态目录:
Alias /functional /path/to/functional/
Alias /phpMyAdmin /path/to/phpMyAdmin/
# ... other aliases omitted ...
<Directory /path/to/functional>
DirectoryIndex index.php
AllowOverride all
</Directory>
我已经尝试了index.php not loading by default 中的大多数答案以使 index.php 加载,但没有成功。我什至不需要指定DirectoryIndex index.php,因为该行已经在 conf.d/php.conf 中。
关于如何解决这个问题的任何想法,Rails 在应该在 Apache 堆栈中的其他地方提供 404 的 URL 上?
【问题讨论】:
标签: apache passenger mod-alias directoryindex