本文介绍了无法通过Passenger/Nginx强迫Rails进入生产环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过Nginx/Ubuntu上的Phusion Passenger在生产环境中运行Rails应用程序.根据 docs ,环境由rails_env选项控制在nginx.conf中...但是无论我们是否指定"rails_env生产",它都以开发模式在我们的机器上运行;或将其忽略(默认为生产状态).

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).

其他说明:

  • Linux环境变量也将RAILS_ENV设置为生产.

  • The Linux environment variableRAILS_ENV is also set to production.

我们可以使用以下命令在生产模式下运行'脚本/服务器-e生产',所以似乎不是Ruby的情况覆盖环境的代码.

We can run in production mode using'script/server -e production', so itdoesn't seem to be a case of Rubycode overriding the environment.

有什么想法吗?

完整的nginx.conf:

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

}

推荐答案

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

添加到config.ru:

Add to config.ru:

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

这篇关于无法通过Passenger/Nginx强迫Rails进入生产环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 12:50