开发者

nginx on separate server proxy_pass to multiple rails apps with sub URI on passenger standalone in different boxes

开发者 https://www.devze.com 2023-03-18 00:34 出处:网络
I have this requirement, where there are multiple rails applications. Each application is deployed in two app servers, (app1 and app2) and they are load balanced through nginx on a separate server (lb

I have this requirement, where there are multiple rails applications. Each application is deployed in two app servers, (app1 and app2) and they are load balanced through nginx on a separate server (lb).

The lb box contains plain vanilla nginx without passenger plugins. The rails applications are deployed on passenger stand alone.

All the rails applications need to run on the same domain but with different sub_uri, like below

http://www.example.com/rails1
http://www.example.com/rails2

I have the lb box nginx configuration something like below.

   http {
      ...
      upstream rails1_cluster {
        ip_hash;
        server app1.server:3001;
        server app2.server:3001;
      }

      upstream rails2_cluster {
        ip_hash;
        server app1.server:3002;
        server app2.server:3002;
      }

      ...

      server {
         server_name www.example.com;
         ...
         ...

         location /rails1 {
              proxy_pass http://rails1_cluster;
              ...
         }

         location /rails2 {
              proxy_p开发者_如何转开发ass http://rails2_cluster;
              ...
         }
         ....
     }
  }

With this setup, the app running on passenger standalone in app1 and app2 throws an error that it is unable to find any route /rails1/.

This article "How To Deploy Phusion Passenger To A Subdirectory, Routing Errors, And Restarting" tries to address the same problem, but it suggests changing the routes, which I don't wish to do. The Rails applications am dealing with are of same code base but customized for specific instances catering to specific client.

In passenger plugin for Nginx server, there is a passenger_base_uri which helps in setting a sub URI for the app. What is the equivalent of the same in case of passenger stand alone? Or am I missing something fundamental here? Any help, suggestions would help.


Give this a try, using the rewrite module:

location /rails2 {
                rewrite "/rails2/" / break;
                proxy_pass http://rails2_cluster;
}

It's a regex so might go on fire if the url actually contains that. Also this one does not yet work for addresses without the trailing slash, so check this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号