How to use different rails_env with nginx, passenger and redmine

空扰寡人 提交于 2019-11-28 09:06:38

问题


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


回答1:


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



回答2:


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:-

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

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


来源:https://stackoverflow.com/questions/5092225/how-to-use-different-rails-env-with-nginx-passenger-and-redmine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!