Can't force Rails into production environment via Passenger/Nginx

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;
        }
    
    }
    

    Workaround found at http://groups.google.com/group/phusion-passenger/browse_thread/thread/f91cd54bd379ad26/0a510133a080daac

    Add to config.ru:

    ENV['RAILS_ENV'] = ENV['RACK_ENV']  if !ENV['RAILS_ENV'] && ENV['RACK_ENV'] 
    

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

    链接地址: http://www.djcxy.com/p/32478.html

    上一篇: Nginx和Phusion Passenger(配置多个虚拟主机)

    下一篇: 无法通过Passenger / Nginx强制Rails进入生产环境