2
votes

I know this is a super-famous error, but i tried quite everything I found here on StackOverflow and on google without being able to solve it.

I have the following configuration:

  • SLES 11 SP1 on Amazon EC2
  • nginx 1.2.2
  • passenger 3.0.15
  • rails 3

I installed nginx and passenger and set the nginx.conf like this:

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;
        }
    }

    ...

When I access the app from the browser it keeps saying 403 forbidden. I also run chmod -R 755 on the app folder, on /var and /opt (nginx is in /opt/nginx)

In the logs, the error is:

[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: The same error appears also for /root/myapp/public/index.html (which doesn't exist)

[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: Same error also when I run passenger in standalone mode:

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

5 Answers

4
votes

Ok, solved. The problem was that nginx requires read permissions for the app files, and execute permission for everything that goes from the root to the app itself.

Running chmod -R 755 on the root solved the problem.

1
votes

I found the root cause come from nginx.conf setting.

I change passenger_enabled on and root path in same block (in location /) and restart nginx. The 403 forbidden error solved.

Here is my sample setting:

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

If all the folder and file permission are set correctly, please check the configuration:

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

You should add least add the three line.

0
votes

Are you missing config.ru?

Missing config.ru caused the error in my case.

Sample 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
-2
votes

According to the erro you posted only that file doesn't have the required permission. Try to run chmod 777 /root/myapp/public/favicon.ico