Nginx 1.2,Passenger 3.0,Rails 3:403禁止错误

时间:2012-08-29 10:53:20

标签: ruby-on-rails nginx amazon-ec2 passenger

我知道这是一个非常着名的错误,但是我在StackOverflow和谷歌上找到的所有内容都无法解决。

我有以下配置:

  • Amazon EC2上的SLES 11 SP1
  • nginx 1.2.2
  • 乘客3.0.15
  • rails 3

我安装了nginx和passenger并设置了nginx.conf,如下所示:

http {
    passenger_root /usr/lib64/ruby/gems/1.8/gems/passenger-3.0.15;
    passenger_ruby /usr/bin/ruby;

    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /root/myapp/public;
            autoindex on;
            passenger_enabled on;
        }
    }

    ...

当我从浏览器访问应用程序时,它一直说403被禁止。 我还在app文件夹上运行chmod -R 755,在/ var和/ opt(nginx在/ opt / nginx中)

在日志中,错误是:

[error] 5240#0: *1 open() "/root/myapp/public/favicon.ico" failed (13: Permission denied), client: 188.11.5.49, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "ec2-54-247-18-139.eu-west-1.compute.amazonaws.com"

更新:/root/myapp/public/index.html也出现了相同的错误(不存在)

[error] 5638#0: *1 "/root/myapp/public/index.html" is forbidden (13: Permission denied), client: 188.11.5.49, server: localhost, request: "GET / HTTP/1.1", host: "ec2-54-247-18-139.eu-west-1.compute.amazonaws.com"

更新2 :当我以独立模式运行乘客时,同样的错误:

You can stop Phusion Passenger Standalone by pressing Ctrl-C.
===============================================================================
2012/08/30 08:31:34 [error] 7834#0: *4 "/root/myapp/public/index.html" is forbidden (13: Permission denied), client: 127.0.0.1, server: _, request: "HEAD / HTTP/1.1", host: "0.0.0.0" 

5 个答案:

答案 0 :(得分:4)

好的,解决了。问题是nginx需要读取应用程序文件的权限,并对从root用户到应用程序本身的所有内容执行权限。

在root上运行chmod -R 755解决了这个问题。

答案 1 :(得分:1)

我发现根本原因来自nginx.conf设置。

我在相同的块(位置/)中更改passenger_enabled和根路径,然后重新启动nginx。 403禁止错误解决了。

以下是我的示例设置:

用户redmine; http {

passenger_root /usr/local/lib/ruby/gems/2.1.0/gems/passenger-4.0.45;
passenger_ruby /usr/local/bin/ruby;
access_log logs/host.access.log;

include       mime.types;
default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

# rails server
server {
    listen       80;
    server_name  localhost;

    location / {
       root /usr/local/redmine-2.5.2/public;    
       passenger_enabled on;
       index  index.html index.htm;
    }
}

                                                           Sam Sheen

答案 2 :(得分:0)

你缺少config.ru吗?

缺少config.ru导致我的错误。

示例Config.ru:

root_dir = File.dirname(__FILE__)
app_file = File.join(root_dir, 'pantube.rb')
require app_file

set :environment, :production #ENV['RACK_ENV'].to_sym
set :root,        root_dir
set :app_file,    app_file
disable :run

run Sinatra::Application

答案 3 :(得分:0)

如果正确设置了所有文件夹和文件权限,请检查配置:

location ~ ^/redmine(/.*|$) {
   passenger_base_uri /redmine;
   passenger_app_root /Users/cc/Dropbox/Work/www/redmine;
   passenger_enabled on;
}

你应该添加最少添加三行。

答案 4 :(得分:-2)

根据您发布的错误,只有该文件没有所需的权限。尝试运行chmod 777 /root/myapp/public/favicon.ico