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.
Your application is probably running in production mode by default. What you're doing is engaging a shell, something using a different environment.
Normally on a production server you'd put this into your profile script:
# Add to ~/.bash_profile
export RAILS_ENV=production
That way when you power up rails c
you will get the correct environment.
As a note, the only way this shell is engaging in the first place is that you have a development
setting in your config/database.yml
. That shouldn't be there, as the configuration for your production server should be production-only.
nginx doesn't run in development or production mode - your app does, via your unicorn configuration and/or the RAILS_ENV environment variable when you launch your unicorn instances.
You should be launching your unicorn instances with the RAILS_ENV
variable prefixed to the command, eg:
RAILS_ENV=production bundle exec unicorn -c config/unicorn.rb -D
rails console
launches a completely different instance which may be in an different environment - it is unrelated to your unicorn instances. If you want to launch a production console instance, then either invoke RAILS_ENV=production rails console
or rails console production
. Note that this has no bearing on the environment that your application runs in.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.