使用Apache和Passenger部署Rails时,我遇到了403错误。

10

我已经安装了所需的工具,并遵循了几个教程尝试使 passenger 响应。

我可以访问 public 文件夹中的静态文件(例如 public/500.html 或 422.hml)。昨天我通过虚拟主机进入,发现了一些 passenger 错误。但过了一会儿主机重新启动了服务,从那时起我就再也无法访问 rails 应用程序了。

链接

链接

链接

这些是我用来配置服务器的一些链接。我还读到可能是权限问题;我已经检查过了,但不确定是否正确。


403禁止错误是权限问题。检查文档根目录,确保index.php具有644权限。还要确保index.php具有用户所有权,与能够访问的500.html相同。 - Leo Prince
这是一个通过apache + passenger工作的Rails应用程序。我可以访问本地文件,如图像。但当Rails应该响应时,却给了我那个错误。 - narc88
4个回答

17

首先检查您的错误日志。默认情况下,它位于/var/log/apache2/

如果您遇到client denied by server configuration问题,请检查您的网站配置文件/etc/apache2/sites-available/your-site.conf是否符合Phusion Passenger用户指南的规定。请注意Require all granted

<Directory "/home/user/folder">
    Require all granted 
    Options FollowSymLinks
    # This relaxes Apache security settings.
    AllowOverride None
    # MultiViews must be turned off.
    Order allow,deny
    Allow from all
</Directory>

1
如果您使用的是Apache >= 2.4,则似乎需要“Require all granted”。 - rogerdpack

5

对我来说,这意味着我正在运行Rails 2.3,并使用Phusion Passenger 5.x。

显然,5.x根本无法与2.2配合使用,在2.3中需要先复制一个config.ru文件(以便Rails使用Rack作为后端)。

2.3的示例config.ru文件:

# Rack Dispatcher

# Require your environment file to bootstrap Rails
require File.dirname(__FILE__) + '/config/environment'

# Dispatch the request
run ActionController::Dispatcher.new

我无法理解为什么没有任何咒语起作用,就好像Passenger忽略了我的Rails应用程序。在我的/var/log/apache2/error.log文件中,我看到了这个:

[Mon May 11 15:47:00.397891 2015] [autoindex:error] [pid 17490:tid 3058694976] [client 216.49.181.251:49248] AH01276: Cannot serve directory /home/x/y/railsapp/public/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive, referer: https://www.google.com/

这让我感到非常困惑,显然意味着"Passenger没有在该虚拟主机上运行"。如果我创建了一个public/index.html文件,Apache可以很好地提供服务,因此这不是权限问题。我还看到了这个,这意味着Passenger启动正常:

[ 2015-05-11 18:23:53.9594 4964/b7415700 agents/Watchdog/Main.cpp:728 ]: All Phusion Passenger agents started!

另请参见 https://www.phusionpassenger.com/documentation/Users%20guide%20Apache%204.0.html#_i_get_a_403_forbidden_error

基本上,使用Passenger 5.x(在发布说明中说不支持Rails 2.2,只有在Rails应用程序的根目录中创建“config.ru”文件才支持2.3。它可以与像Rails 2.3这样的旧版本的Rack一起使用,只需删除较新的Rack gem并安装1.1.6或其他版本,如果有任何vendored Rack gems,请将其删除。祝好运!

另外顺带一提,这条消息:

[Mon May 11 18:25:10.235574 2015] [core:alert] [pid 5263:tid 3017780032] [client 127.0.0.1:56737] /home/rdp/dev/prod_flds/public/.htaccess: Invalid command 'RewriteEngine',也许拼写错误或由未包含在服务器配置中的模块定义

意思是“删除您的public/.htaccess文件,通常不需要使用乘客”


哇,解释得很好。config.ru文件里会放什么内容? - Serge Pedroza
1
@SurgePedroza 顺便说一下,这是我的样子。 - rogerdpack

2

我在Mac OS 10.9上使用Apache和Passenger运行Rails时,也遇到了403错误(Unix类系统)。

以下是一些提示:

  1. You can check apache log directory and see the what happened. The directory: /var/log/apache2/error_log.
  2. Issue: Permission denied: access to / denied ( filesystem path 'path_apache_access' ) because search permissions are missing on a component of the path.

    Check 'path_apache_access' by CLI: ls -ld 'path_apache_access' and use chmod +x to change the path privilege.

    Also, note this: Httpd Wiki - (13) Permission Denied-.

  3. Issue: configuration error: couldn't perform authentication. AuthType not set!.

    Issue: client denied by server configuration.

    Go to /etc/apache2/httpd.conf and take a look on <Directory> tag.

    Check apache version by CLI: apachectl -v, if Apache < 2.4, do NOT uncomment "Require all granted".

    <Directory "rails_app_directory/public">
          # This relaxes Apache security settings.
          AllowOverride all
          # MultiViews must be turned off.
          Options -MultiViews
          # Uncomment this if you're on Apache >= 2.4:
          # Require all granted
          Options FollowSymLinks
          Order allow,deny
          Allow from all
    </Directory>
    

1
回答是乘客给了我403,因为我必须在Apache配置中设置环境变量“RackEnv”为“development”(在我的情况下)。

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