我有一个站点,Ruby on Rails通过Phusion Passenger在根目录下运行。某些Apache Alias
指令提供静态HTML目录。Apache DirectoryIndex指令在Ruby on Rails上无法正常工作
如果您从某个静态目录请求一个文件的确切URL,Apache会按照预期返回它。但是,有一些情况我没有得到预期的行为。考虑别名Alias /functional /path/to/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文件到功能目录(除了的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大部分的答案,使指数.php加载,以no为准。我甚至不需要指定DirectoryIndex index.php
,因为该行已经在conf.d/php.conf中。
有关如何解决这个问题的任何想法,其中Rails提供404s应该在Apache堆栈中的其他地方的URL?