Nginx

Nginx、Passenger、Rails 提供靜態文件但不執行應用程序

  • December 4, 2013

我見過其他類似的問題,但沒有一個令人滿意的答案,所以就這樣吧。我已經安裝了 Ruby、Rails、Nginx 和Passenger,並嘗試將它們配置為一起工作。

這是相關部分/opt/nginx/conf/nginx.conf

server { 
   listen 80; 
   server_name .myapp.dev; # There is an entry in my local /etc/hosts file for this

   passenger_enabled on; 

   root            /srv/www/myapp.dev/public;
   access_log      /srv/www/myapp.dev/logs/access_log;
   error_log       /srv/www/myapp.dev/logs/error_log warn;
}

還有另一個server塊,但它正在監聽,localhost所以我認為它不會引起任何問題。

這是輸出ls -la /srv/www/myapp.dev/

drwxr-xr-x 3 josh josh 4096 Dec  4 19:12 .
drwxr-xr-x 3 josh josh 4096 Dec  4 18:34 ..
drwxr-xr-x 2 josh josh 4096 Dec  4 18:34 logs
lrwxrwxrwx 1 josh josh   37 Dec  4 19:12 public -> /home/josh/rails/myapp/public

我想知道是否可能存在權限錯誤,但我沒有看到任何錯誤表明它甚至正在嘗試執行 Ruby。

/opt/nginx/logs/error.log是重新啟動 nginx 時添加的內容

[ 2013-12-04 20:16:17.9953 2321/b6fea000 agents/Watchdog/Main.cpp:574 ]: Options: { 'analytics_log_user' => 'nobody', 'default_group' => 'nogroup', 'default_python' => 'python', 'default_ruby' => '/home/josh/.rvm/wrappers/ruby-2.0.0-p353/ruby', 'default_user' => 'nobody', 'log_level' => '0', 'max_instances_per_app' => '0', 'max_pool_size' => '6', 'passenger_root' => '/home/josh/.rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.26', 'pool_idle_time' => '300', 'temp_dir' => '/tmp', 'union_station_gateway_address' => 'gateway.unionstationapp.com', 'union_station_gateway_port' => '443', 'user_switching' => 'true', 'web_server_passenger_version' => '4.0.26', 'web_server_pid' => '2320', 'web_server_type' => 'nginx', 'web_server_worker_gid' => '65534', 'web_server_worker_uid' => '65534' }
[ 2013-12-04 20:16:18.0527 2324/b6f0b000 agents/HelperAgent/Main.cpp:626 ]: PassengerHelperAgent online, listening at unix:/tmp/passenger.1.0.2320/generation-0/request
[ 2013-12-04 20:16:18.1577 2329/b6683000 agents/LoggingAgent/Main.cpp:318 ]: PassengerLoggingAgent online, listening at unix:/tmp/passenger.1.0.2320/generation-0/logging
[ 2013-12-04 20:16:18.1644 2321/b6fea000 agents/Watchdog/Main.cpp:761 ]: All Phusion Passenger agents started!

Nginx 提供靜態文件,例如,如果我訪問 myapp.dev/500.html,那麼我會看到預設的 Rails 500 錯誤頁面。日誌中提到了 Phusion Passenger,因此它似乎正在工作(即使它是error.log,結果似乎也不是負面的)。

我正在撕扯我的頭髮試圖讓它發揮作用。有人有什麼想法嗎?

編輯

這是輸出rake routes

rake routes
  Prefix Verb   URI Pattern               Controller#Action
   posts GET    /posts(.:format)          posts#index
         POST   /posts(.:format)          posts#create
new_post GET    /posts/new(.:format)      posts#new
edit_post GET    /posts/:id/edit(.:format) posts#edit
    post GET    /posts/:id(.:format)      posts#show
         PATCH  /posts/:id(.:format)      posts#update
         PUT    /posts/:id(.:format)      posts#update
         DELETE /posts/:id(.:format)      posts#destroy
    root GET    /                         posts#index

但訪問myapp.dev/posts回報404

乘客找不到您的申請……

換成root /srv/www/myapp.dev/public;_ root /home/josh/rails/myapp/public;

引用自:https://serverfault.com/questions/559272