2

我知道这是一个非常著名的错误,但我尝试了我在 StackOverflow 和谷歌上找到的所有东西,但无法解决它。

我有以下配置:

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

我安装了 nginx 和乘客,并像这样设置 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 文件夹、/var 和 /opt 上运行 chmod -R 755(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" 
4

5 回答 5

4

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

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

于 2012-08-30T08:45:47.827 回答
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
于 2014-07-13T22:30:00.067 回答
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
于 2013-07-15T04:45:27.807 回答
0

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

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

您应该添加至少添加三行。

于 2014-02-27T02:11:01.310 回答
-2

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

于 2012-08-29T11:39:10.530 回答