2012-08-29 60 views
1

我知道這是一個超級着名的錯誤,但我嘗試了我在StackOverflow和Google上找到的所有內容,但都無法解決它。Nginx 1.2,Passenger 3.0,Rails 3:403禁止錯誤

我具有以下配置:

  • SLES在Amazon EC2
  • nginx的1.2.2
  • 乘客3.0.15
  • 導軌3

我安裝nginx的11 SP1和乘客,並像這樣設置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被禁止。 我還請運行chmod -R 755上的應用程序文件夾中,上/ var和/選擇(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" 

UPDATE :還出現/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" 

UPDATE 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

好的,解決了。問題在於nginx需要讀取應用程序文件的權限,並執行從根節點到應用程序本身的所有內容的權限。

運行chmod -R 755就解決了問題的根源。

0

根據錯誤您只發布該文件沒有所需的權限。嘗試運行chmod 777 /root/myapp/public/favicon.ico

+0

它沒有工作:( – lucaronin

+0

嘗試重新啓動nginx的服務器。 –

+0

已經嘗試過,什麼都沒有改變.. – lucaronin

0

你是否缺少config.ru?

Missing 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 
0

如果所有的文件夾和文件的權限設置是否正確,請檢查配置:

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

您應該添加至少增加三線。

1

我發現根本原因來自nginx.conf設置。

我在同一個塊(在位置/)更改passenger_enabled和根路徑,然後重新啓動nginx。解決了403禁止的錯誤。

這是我的示例設置:

user 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