views:

816

answers:

2

Hi-

I'm having trouble getting a Rails app to run in the production environment via Phusion Passenger on Nginx/Ubuntu. According to the docs, the environment is controlled by the rails_env option in nginx.conf ... but it runs in development mode on our box regardless of whether we specify 'rails_env production;' or leave it out (the default is said to be production).

Other notes:

  • The Linux environment variable RAILS_ENV is also set to production.

  • We can run in production mode using 'script/server -e production', so it doesn't seem to be a case of Ruby code overriding the environment.

Any ideas?

Full nginx.conf:

worker_processes  1;

pid /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    passenger_root /var/lib/gems/1.8/gems/passenger-2.2.7;
    passenger_ruby /usr/bin/ruby1.8;

    include       mime.types;
    default_type  application/octet-stream;

    access_log  /var/log/nginx/access.log;
    error_log  /var/log/nginx/error.log;

    sendfile        on;
    keepalive_timeout  65;

    gzip  on;
    gzip_http_version 1.0;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_buffers 16 8k;

    server {
        listen 80;
        server_name bar.foo.com;
        root /home/foo/dev/bar/public;
        passenger_enabled on;
        rails_env production;
    }

}
A: 

Workaround found at http://groups.google.com/group/phusion-passenger/browse%5Fthread/thread/f91cd54bd379ad26/0a510133a080daac

Add to config.ru:

ENV['RAILS_ENV'] = ENV['RACK_ENV']  if !ENV['RAILS_ENV'] && ENV['RACK_ENV'] 
BFB
A: 

Or try just removing 'config.ru' altogether. Nginx is smart about rails apps, and config.ru is not necessary for them.

Ben