2017-08-26 3 views
0

Nginx 1.12.1でUbuntu 16.04サーバーをセットアップし、正常に動作するようにPhusion Passenger 5.1.8(オープンソース)をインストールして構成しました。Sinatra JSONルートでNginxが動作しない

私はこれをpassenger-ruby-sinatra-demoレポでテストしました。

私は/etc/nginx/sites-available/defaultファイルにレポの/viewsフォルダへroot VARを設定しました:

root /var/www/passenger-ruby-sinatra-demo/views; 

/viewsフォルダはindex.erbと呼ばれる一つのファイルが含まれています。 /を訪れた際だから今、私はhtmlページを参照してください

require 'sinatra/base' 
require 'json' 

class ExampleApp < Sinatra::Base 
    get '/' do 
    erb :index 
    end 

    get '/hello' do 
    content_type 'application/json' 

    {'message'=>'hello world!'}.to_json 
    end 
end 

はここapp.rbファイルの内容です。しかし、/helloにアクセスすると404画面が表示されます。

私は間違っていますか?

更新: helloという名前の空のフォルダをviewsフォルダに追加すると機能します。

答えて

0

serverブロック内の)私の/etc/nginx/sites-available/default設定ファイルに以下を追加することで、これを解決:

... 

location/{ 
    try_files $uri @app; 
} 

location @app { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
} 

... 

そして、私は削除:

location/{ 
    # First attempt to serve request as file, then 
    # as directory, then fall back to displaying a 404. 
    try_files $uri $uri/ =404; 
} 

をこれが削除に関連nginxの設定の問題でした上のコード。

関連する問題