Sinatra on Nginx configuration - what's wrong?

2019-03-27 08:59发布

问题:

I followed this tutorial more or less... I installed the passenger gem, executed passenger-install-ginx-module, sucessfully installed nginx and inserted this into the config:

server {
  listen 80;
  server_name localhost;
  root /home/admin/sintest/public;   # <--- be sure to point to 'public'!
  passenger_enabled on;
}

In /home/admin/sintest I have: an empty public folder, the config.ru:

require 'sinatra'

set :env,  :production
disable :run

require './app.rb'    #the app itself

run Sinatra::Application

and a test sinatra app.rb:

require 'sinatra'

get '/' do
  "hello world!"
end

Now when I run nginx and open up http://localhost what I get is: 403 Forbidden

What am I doing wrong? Have I missed something?

回答1:

Make sure that the user nginx is running as (in most cases 'nobody' or 'www-data') has permission to read the contents of your home directory /home/admin.

Also you can look into the nginx logs and read exactly what the error was.



回答2:

I had the same error until I added passenger_root and passenger_ruby directives in the http block.