如何将不同的rails_env与nginx、passenger和redmine一起使用
我需要将 redmine 与 nginx、phusion guest 和 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 设置为内部。
问题是,nginx 仅对两个 redmine 实例使用两个rails_env 之一,而不是每个实例使用一个。有什么建议如何将不同的rails_env与相同的应用程序、nginx和phusion乘客一起使用吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你也遇到了和我一样的问题。您希望使用相同的物理目录来托管应用程序实例,但希望通过使用不同的 DNS 条目(redmine.development / redmine.Production)在不同环境(开发/生产)下与应用程序进行交互???
问题是乘客将传入的请求识别为使用在根目录上方的目录中找到的 Rails 应用程序。如果您在多个 nginx 配置中对 root 使用相同的文字引用,passenger 会将请求转发到 root 中找到的单个运行实例。即,如果您首先启动开发应用程序,然后尝试通过 redmine.Production 访问生产环境,您最终将与开发环境进行交互。但是,如果您首先启动生产应用程序,然后尝试访问 redmine.development,您最终将与生产环境进行交互。
答案是为您要运行的每个环境建立应用程序目录的符号链接。 Passenger 仅查看根的字面路径 - 如果它与当前正在运行的实例不匹配,它将生成一个新实例。
例如)
物理根是
~/rails_apps/myserver
(其中 myserver 包含 app、public 等)创建一个名为
~/rails_apps/dev.myserver
的符号链接到~/rails_apps/myserver
和另一个名为~/rails_apps/pro.myserver
的~/rails_apps/myserver
。现在,在您的 nginx 配置中,以 root 身份使用公共文件夹的符号链接位置。
例如,如果符号链接 /home/user/rails_apps/[dev|pro].redmine 指向 /home/user/rails_apps/redmine)
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)
nginx乘客多次不遵循.../app/public目录的符号链接
因为它希望它是一个目录而不是文件
但是您可以使用 PASSENGER_APP_GROUP_NAME 指令。
像这样:-
nginx passenger doesnt follow symlink of .../app/public directory many time
because it expect it to be a directory not file
However you can use PASSENGER_APP_GROUP_NAME directive.
like this:-