无法让nginx在生产中使用Rails应用程序
我有一个Rails应用程序,它在Webrick的本地机器上运行良好。 我尝试将其部署到AWS EC2。 我已将我的应用程序源从bitbucket复制到/home/ubuntu
并通过此命令安装了nginx和passenger(以及其他所需的所有内容,如gem,ruby等):
rvmsudo passenger-install-nginx-module
然后我这样做了:
$ git clone git://github.com/jnstq/rails-nginx-passenger-ubuntu.git $ sudo mv rails-nginx-passenger-ubuntu/nginx/nginx /etc/init.d/nginx $ sudo chown root:root /etc/init.d/nginx
Nginx本身运行良好(!),例如:
$ sudo /etc/init.d/nginx restart * Stopping Nginx Server... [ OK ] * Starting Nginx Server... [ OK ]
它安装在/ opt / nginx中,即使这样我也必须使用/etc/init.d/nginx来控制它的状态。 这是我的/opt/nginx/nginx.conf文件:
server { listen 80; server_name localhost; root /home/ubuntu/my_app/public/; passenger_enabled on; }
但是,除了public/index.html
,它不会显示任何内容。 找不到任何其他东西。 如果我删除public/index.html
那么它总是返回404。
当然,这不是我想要的。 我希望它作为普通的Rails应用程序工作:
MyApp::Application.routes.draw do get "about" => "home#about" get "contacts" => "home#contacts" root to: "public#home" # I have PublicController and action called home end
不像一个有静态网页的网站。
$ ls /opt/nginx/logs access.log error.log nginx.pid $ cat error.log [ 2014-09-15 06:28:30.4247 18366/7f9bb38ab780 agents/Watchdog/Main.cpp:728 ]: All Phusion Passenger agents started! App 1395 stdout: App 1395 stderr: DEPRECATION WARNING: Support for Rails < 3.2.13 will be dropped from Formtastic 3.0. (called from require at /home/ubuntu/.rvm/gems/ruby-1.9.3-p547@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76) App 18402 stdout: App 18402 stderr: DEPRECATION WARNING: Support for Rails < 3.2.13 will be dropped from Formtastic 3.0. (called from require at /home/ubuntu/.rvm/gems/ruby-1.9.3-p547@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76) App 18402 stderr: App 18402 stderr: [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message. App 18402 stderr: [ 2014-09-15 06:28:49.3217 18369/7f3cc4259700 Pool2/SmartSpawner.h:298 ]: Preloader for /home/ubuntu/my_app started on PID 18402, listening on unix:/tmp/passenger.1.0.18365/generation-0/backends/preloader.11znc5q App 19153 stdout: App 18402 stderr: [DEPRECATED] The 'safe' write concern option has been deprecated in favor of 'w'. App 18402 stderr: App 18402 stderr: cache: [GET /456] miss App 18402 stderr: cache: [GET /public/home] miss App 18402 stderr: WARN: tilt autoloading 'sass' in a non thread-safe way; explicit require 'sass' suggested. App 18402 stderr: App 18402 stderr: cache: [GET /] miss
和
App 1395 stderr: App 1395 stderr: cache: [GET /] miss App 1395 stderr: cache: [GET /home/index] miss App 1395 stderr: cache: [GET /public/home] miss App 1395 stderr: cache: [GET /fdsfd] miss App 1395 stderr: cache: [GET /public] miss App 1395 stderr: cache: [GET /public/home] miss App 1395 stderr: cache: [GET /public/hoe] miss App 1395 stderr: cache: [GET /manager/html] miss App 1395 stderr: cache: [GET /clientaccesspolicy.xml] miss App 1395 stderr: cache: [GET /hello.html] miss
我做错了什么?