我正在使用 Debian 升级到新的 linode。我安装了 rvm、ruby 企业版、passenger、nginx(通过passenger)、rails 2.3 lts。我的应用程序使用脚本/服务器。我使用 nginx 来提供静态文件。但是当我前往 Rails 路线时,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"
我读了 3 个解决方案https://www.phusionpassenger.com/library/admin/nginx/troubleshooting/ruby/并在 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,重新启动并尝试加载示例应用页面:
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/
答案1
我找到了答案。我需要将 config.ru 文件添加到我的 rails 项目的根目录中:
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