2
votes

I've looked through a ton of posts but I just can't get past this 403 Forbidden error. I have:

  1. Updated nginx user permissions on website folder
  2. Updated passenger_ruby to use RVM wrapper directory
  3. Confirmed passenger_root path with passenger-config --root

I'm still getting a 403 and can't seem to find what I am missing.

Here are my files below.

Folder Structure (755 www-data):

--website
----app
----public
----tmp
----views
----config.ru

config.ru:

require 'rubygems'
require 'sinatra'

set :environment, ENV['RACK_ENV'].to_sym
disable :run, :reload

require File.expand_path '../app/main.rb', __FILE__

run Sinatra::Application

Server .conf:

server {
  listen 80;
  server_name website.com;

  root /www/website/public;   # <--- be sure to point to 'public'!
  passenger_enabled on;
}

Nginx .conf:

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/local/rvm/wrappers/ruby-2.2.1/ruby;

Example main.rb:

 Require 'slim'
 get "/"
     slim: index
 do

Sites Error Log:

2015/07/28 19:09:45 [error] 34000#0: *2 directory index of "/www/website/public/" is forbidden, client: 0.0.0.0, server: website.com, request: "GET / HTTP/1.1", host: "website.com"
2
Can you post relevant messages from the Nginx error log file?Hongli
I've added the error log info.Korben Dallas
For any future viewers I finally got it working with nginx and unicorn as deatiled in the sinatra docs hereKorben Dallas

2 Answers

0
votes

Try following this: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-nginx-on-ubuntu-14-04

If you already have passenger configured, just skip that and work on the nginx configuration.

0
votes

I'm just beginning with Ruby|Sinatra|Passenger|Nginx and I had the same obscure problem.

After a lot of hacking around the following configuration worked for me. It's probably not perfect but I hope it helps someone else get through this problem.

Folder Structure (755 www-data):

--sinatra_test
----public #added this blank dir
----tmp    #added this blank dir
----config.ru
----SinatraTest.rb

config.ru:

require File.absolute_path("SinatraTest.rb")
run SinatraTest

SinatraTest.rb:

require 'sinatra/base'

class SinatraTest < Sinatra::Base
    get '/' do
      "Hello World"
    end
end

Nginx .conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

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

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        gzip on;
        gzip_disable "msie6";

        passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
        passenger_ruby /home/myusername/.rvm/gems/ruby-2.4.0/wrappers/ruby;

        server {
                listen 80;
                server_name myservername.com;

                # Tell Nginx and Passenger where your app's 'public' directory is
                root /home/myusername/sinatra_test/public;

                passenger_enabled on;
        }
}