403 nginx + passenger + sinatra禁止

时间:2015-07-28 22:01:26

标签: ruby nginx sinatra passenger

我查看了很多帖子,但我无法理解这个403 Forbidden错误。我有:

  1. 更新了网站文件夹
  2. 上的nginx用户权限
  3. 更新了passenger_ruby以使用RVM包装器目录
  4. 使用passenger-config确认passenger_root路径--root
  5. 我仍然得到了403,但似乎无法找到我所缺少的东西。

    以下是我的文件。

    文件夹结构(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
    

    服务器.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;
    

    示例main.rb

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

    网站错误日志:

    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 个答案:

答案 0 :(得分:0)

请尝试以下操作:https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-nginx-on-ubuntu-14-04

如果您已经配置了乘客,只需跳过它并处理nginx配置。

答案 1 :(得分:0)

我刚开始使用Ruby | Sinatra | Passenger | Nginx,我遇到了同样模糊的问题。

经过大量的黑客攻击后,以下配置为我工作。它可能并不完美但我希望它可以帮助其他人解决这个问题。

文件夹结构(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;
        }
}