如何在Nginx,Passenger和Redmine中使用不同的rails_env [英] How to use different rails_env with nginx, passenger and redmine

查看:110
本文介绍了如何在Nginx,Passenger和Redmine中使用不同的rails_env的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将Redmine与nginx,phusion passenger和mysql结合使用.由于该项目需要几个redmine实例(应使用不同的rails_env来实现),因此我尝试使用nginx将它们设置在不同的服务器虚拟主机中.

一个虚拟主机的示例:

server {
    listen xxxx;
    server_name redmine.xxxxx;
    root /xxxxx/redmine/public;
    passenger_enabled on;
    rails_env production;
}

另一个服务器虚拟主机也是如此,但是server_name与另一个域匹配,并且rails_env设置为internal.

问题是,nginx对于两个redmine实例都只使用两个rails_env之一,而不是每个实例.有什么建议如何在同一个应用程序中使用不同的rails_env?

谢谢

解决方案

我认为您遇到的问题与我相同.您想使用相同的物理目录来承载应用程序实例,但是您想通过使用不同的DNS条目(redmine.development/redmine.production)在不同的环境(开发/生产)下与应用程序进行交互?

问题在于,乘客使用在根目录上方的目录中找到的rails应用程序识别出传入的请求.如果您在多个Nginx配置中对root使用相同的文字引用,passenger会将请求转发到root中找到的单个运行实例.即,如果您首先启动开发应用程序,然后尝试通过redmine.production访问生产,则最终将与开发环境进行交互.但是,如果首先启动生产应用程序,然后尝试访问redmine.development,则最终将与生产进行交互.

答案是为要运行的每个环境符号链接应用程序的目录.乘客只会查看根目录的字面路径-如果它与当前正在运行的实例不匹配,它将生成一个新的实例.

例如.

物理根为~/rails_apps/myserver(myserver包含应用程序,公共目录等)

创建一个名为~/rails_apps/dev.myserver~/rails_apps/myserver的符号链接,并创建另一个名为~/rails_apps/pro.myserver~/rails_apps/myserver的符号链接.

现在,在您的nginx配置中,以超级用户身份使用指向公共文件夹的符号链接位置.

例如,如果symlink/home/user/rails_apps/[dev|pro].redmine指向/home/user/rails_apps/redmine)

server {
    listen xxxx;
    server_name redmine.development;
    root /home/user/rails_apps/dev.redmine/public;
    passenger_enabled on;
    rails_env development;
}
server {
    listen xxxx;
    server_name redmine.production;
    root /home/user/rails_apps/pro.redmine/public;
    passenger_enabled on;
    rails_env production;
}

I need to have redmine running in combination with nginx, phusion passenger and mysql. Because of the project requires several instances of redmine, which should be realized using different rails_env, I tried to set them in the different server vhosts with nginx.

Example of one vhost:

server {
    listen xxxx;
    server_name redmine.xxxxx;
    root /xxxxx/redmine/public;
    passenger_enabled on;
    rails_env production;
}

Same goes for the other server vhost, but there server_name is matched to the other domain and rails_env set to internal.

The problem is, that nginx just uses one of both rails_env for both redmine instances, not one for each. Any advice how to use different rails_env with the same application, nginx and phusion passenger?

Thanks

解决方案

I think you're having the same problem I had. You want to use the same physical directory to host the application instances but you want to interact with the app under different environments (development/production) by using different DNS entries (redmine.development / redmine.production)???

The problem is that passenger recognizes the incoming request as using the rails app found in the directory above root. If you're using the same literal reference for root in multiple nginx configs, passenger will forward the request to the single running instance found in root. i.e., if you start up your development application first, then try to access production via redmine.production, you'll end up interacting with the development environment. However if you start up your production app first, then try to access redmine.development, you'll end up interacting with production.

The answer is to symlink your app's directory for every environment you want to run. Passenger only looks at the literal path to root - if it doesn't match a currently running instance, it'll spawn a new one.

ex.)

Physical root is ~/rails_apps/myserver (where myserver contains app, public, etc.)

Create a symlink called ~/rails_apps/dev.myserver to ~/rails_apps/myserver and another one called ~/rails_apps/pro.myserver to ~/rails_apps/myserver.

Now inside your nginx config, use the symlink locations to the public folder as root.

ex., if symlink /home/user/rails_apps/[dev|pro].redmine points to /home/user/rails_apps/redmine)

server {
    listen xxxx;
    server_name redmine.development;
    root /home/user/rails_apps/dev.redmine/public;
    passenger_enabled on;
    rails_env development;
}
server {
    listen xxxx;
    server_name redmine.production;
    root /home/user/rails_apps/pro.redmine/public;
    passenger_enabled on;
    rails_env production;
}

这篇关于如何在Nginx,Passenger和Redmine中使用不同的rails_env的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆