Nginx

nginx沒有通過乘客將任何請求傳遞給rails 2.3

  • January 1, 2016

我正在使用 Debian 升級到新的 linode。我安裝了 rvm、ruby 企業版、passenger、nginx(通過passenger)、rails 2.3 lts。我的應用程序適用於腳本/伺服器。我讓 nginx 提供靜態文件。但是當我去 rails route 時,nginx 的行為就像乘客不存在一樣。我製作了一個新的測試應用程序和一個簡化的 nginx.conf,結果相同。我在日誌中沒有看到乘客的錯誤。

基本問題是 nginx 尋找靜態文件而不是生成 rails:

2016/01/01 17:18:00 [error] 4820#0: *10 open() "/home/curi/www/testapp/public/test/foo" failed (2: No such file or directory), client: 73.241.61.62, server: , request: "GET /test/foo HTTP/1.1", host: "45.79.64.233"

我在https://www.phusionpassenger.com/library/admin/nginx/troubleshooting/ruby/上閱讀了 3 個解決方案並用Google搜尋了很多,但我仍然卡住了。細節:

帶有乘客日誌級別 3 的範例 nginx 錯誤日誌:

[ 2016-01-01 12:10:34.3961 3468/7efdc8705780 age/Wat/WatchdogMain.cpp:1276 ]: Starting Passenger watchdog...
[ 2016-01-01 12:10:34.4108 3474/7fdae531f780 age/Cor/CoreMain.cpp:957 ]: Starting Passenger core...
[ 2016-01-01 12:10:34.4111 3474/7fdae531f780 age/Cor/CoreMain.cpp:234 ]: Passenger core running in multi-application mode.
[ 2016-01-01 12:10:34.4127 3474/7fdae531f780 age/Cor/CoreMain.cpp:707 ]: Passenger core online, PID 3474
[ 2016-01-01 12:10:34.4232 3482/7f90f019e780 age/Ust/UstRouterMain.cpp:504 ]: Starting Passenger UstRouter...
[ 2016-01-01 12:10:34.4238 3482/7f90f019e780 age/Ust/UstRouterMain.cpp:317 ]: Passenger UstRouter online, PID 3482
2016/01/01 12:10:44 [error] 3494#0: *2 open() "/home/curi/www/curius/current/public/1" failed (2: No such file or directory), client: 73.241.61.62, server: , request: "GET /1 HTTP/1.1", host: "45.79.64.233"

乘客日誌級別 7,重新啟動並嘗試載入範例應用程序頁面:

http://pastebin.com/Kr6Ccx9T

nginx.conf:

worker_processes  1; # nginx workers

events {
   worker_connections  1024;
}

http {
   passenger_root /home/curi/.rvm/gems/ree-1.8.7-2012.02/gems/passenger-5.0.23;
   passenger_ruby /home/curi/.rvm/gems/ree-1.8.7-2012.02/wrappers/ruby;
   # passenger_ruby /home/curi/.rvm/rubies/ree-1.8.7-2012.02/bin/ruby; # i tried both
   passenger_log_level 7; # 3 default, 7 max
   rewrite_log  on;
   error_log  logs/error.log  notice;


  server {
     listen 80 default_server;
     root /home/curi/www/testapp/public;   # <--- be sure to point to 'public'!
     passenger_enabled on;
     rails_env production;
  }
}

我也嘗試過設置 server_name 。我用舊伺服器上的更複雜的工作配置(只是passenger_root和passenger_ruby改變了)嘗試了它。結果相同。

版本:

curi@curius:/opt/nginx/logs$ nginx -V
nginx version: nginx/1.8.0
built by gcc 4.9.2 (Debian 4.9.2-10) 
built with OpenSSL 1.0.1k 8 Jan 2015
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-cc-opt=-Wno-error --with-ld-opt= --with-pcre=/tmp/passenger.1n7nxq7/pcre-8.34 --add-module=/home/curi/.rvm/gems/ree-1.8.7-2012.02/gems/passenger-5.0.23/src/nginx_module
curi@curius:/opt/nginx/logs$ which ruby
/home/curi/.rvm/rubies/ree-1.8.7-2012.02/bin/ruby
curi@curius:/opt/nginx/logs$ passenger-config --root
/home/curi/.rvm/gems/ree-1.8.7-2012.02/gems/passenger-5.0.23
curi@curius:/opt/nginx/logs$ ruby -v
ruby 1.8.7 (2013-06-27 MBARI 8/0x6770 on patchlevel 374) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2012.02
curi@curius:/opt/nginx/logs$ gem list passenger

*** LOCAL GEMS ***

passenger (5.0.23)
curi@curius:/opt/nginx/logs$ gem list rails

*** LOCAL GEMS ***

rails (2.3.18.14)
railslts-version (2.3.18.14)
curi@curius:/opt/nginx/logs$ uname -a
Linux curius 4.1.5-x86_64-linode61 #7 SMP Mon Aug 24 13:46:31 EDT 2015 x86_64 GNU/Linux
curi@curius:/opt/nginx/logs$ cat /etc/debian_version
8.2
curi@curius:/opt/nginx/logs$ gem env
RubyGems Environment:
 - RUBYGEMS VERSION: 1.4.2
 - RUBY VERSION: 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
 - INSTALLATION DIRECTORY: /home/curi/.rvm/gems/ree-1.8.7-2012.02
 - RUBY EXECUTABLE: /home/curi/.rvm/rubies/ree-1.8.7-2012.02/bin/ruby
 - EXECUTABLE DIRECTORY: /home/curi/.rvm/gems/ree-1.8.7-2012.02/bin
 - RUBYGEMS PLATFORMS:
   - ruby
   - x86_64-linux
 - GEM PATHS:
    - /home/curi/.rvm/gems/ree-1.8.7-2012.02
    - /home/curi/.rvm/gems/ree-1.8.7-2012.02@global
 - GEM CONFIGURATION:
    - :update_sources => true
    - :verbose => true
    - :benchmark => false
    - :backtrace => false
    - :bulk_threshold => 1000
 - REMOTE SOURCES:
    - http://rubygems.org/

我找到了答案。我需要在我的 rails 項目的根目錄中添加一個 config.ru 文件:

https://blog.phusion.nl/2015/03/04/phusion-passenger-5-0-1-released/#rails_2_3

# Require your environment file to bootstrap Rails
require ::File.dirname(__FILE__) + '/config/environment'

# Serve static assets from RAILS_ROOT/public directory
# use Rails::Rack::Static
# Dispatch the request
run ActionController::Dispatcher.new

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