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

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

问题描述

我需要将 redmine 与 nginx、phusion 乘客和 mysql 结合运行.因为项目需要几个redmine的实例,应该用不同的rails_env来实现,我试着用nginx设置在不同的server vhosts中.

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.

一个虚拟主机的例子:

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

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

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

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

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?

谢谢

推荐答案

我想你遇到了和我一样的问题.您想使用相同的物理目录来托管应用程序实例,但您想通过使用不同的 DNS 条目(redmine.development/redmine.production)与不同环境(开发/生产)下的应用程序进行交互???

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

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

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.

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

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.

例如)

物理根是 ~/rails_apps/myserver(其中 myserver 包含 app、public 等)

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

创建一个名为 ~/rails_apps/dev.myserver 的符号链接到 ~/rails_apps/myserver 和另一个名为 ~/rails_apps/pro.myserver 的符号链接code> 到 ~/rails_apps/myserver.

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

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

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

例如,如果符号链接/home/user/rails_apps/[dev|pro].redmine 指向/home/user/rails_apps/redmine)

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天全站免登陆