How to force NginX into production mode in Rails 4?

June 13, 2014 3.1k views
I am running a Rails 4 app on a VPS with Ubuntu, NginX and Unicorn. When I SSL into my server and update the app via git or run rake tasks on the database, my app always switches to `development` mode and I can't get it into `production` mode. Typing `RAILS_ENV=production` seems to have no effect at all. When I do $ rails console $ Rails.env I get > --> development all the time. What must I do to force NginX into `production` mode? Actually, I don't want Nginx to **ever** run in `development` mode. How can this be achieved? Thanks for any help.
1 Answer
It's not nginx that is running in development mode. It's your application. When you start your application with unicorn_rails, pass -E production to start it in production mode.
  • Thanks but actually I've never used unicorn_rails before. I used to just say "service unicorn restart". And it worked. When I run "unicorn_rails -E production" I get a bunch of errors like: "E, [2014-06-13T19:56:16.625524 #13919] ERROR -- : adding listener failed addr= (in use)" What am I missing?
  • It's saying something is already running on port 8080. It's in use. If you want to use <code>service unicorn restart</code> you can probably configure it to run in production. What's the upstart or init script you're using look like?

Have another answer? Share your knowledge.