vendredi 5 juin 2015

How to configure Rails 3 app hosted on sub-url with Puma and nginx?

With Phusion Passenger, there are specific directives to use in the nginx virtual host configuration that allow Rails apps to be hosted on sub-urls. This is described in the Phusion Passenger documentation.

With Puma, I am using sockets. My nginx config includes:

upstream subapp {
    server unix:<path_to_subapp_folder>/shared/sockets/puma.sock fail_timeout=0;
}

server {
...
    location /subapp {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://subapp;
    }
}

The sub app receives the GET as '/subapp' but of course doesn't know what to do with it. If I use URL rewriting and pass it everything in the URL after '/subapp', it renders the page, but all links, including asset paths, do not include '/subapp', and as such are invalid.

How does one configure Rails so that it prepends '/subapp' to the paths? I did manage to use a scope in routes.rb (scope(:path => (is_dev? ? '' : '/subapp')) do) but this seemed artificial and it didn't prepend to asset paths. I imagine there is a way to configure nginx/Puma (as one can with Passenger) to deal with this situation.

Aucun commentaire:

Enregistrer un commentaire