Rails app served via Passenger standalone behind an nginx proxy

97 views
Skip to first unread message

David Susco

unread,
Jun 4, 2015, 10:52:24 AM6/4/15
to phusion-...@googlegroups.com
I posted this on stackoverflow, but I thought I'd try here as well:

I have two apps: /foo and /bar. In each of those folders I'm starting up passenger. For foo:

passenger start -d -e production -p 4000

And for bar:

passenger start -d -e production -p 4001

I then have nginx configured like so:

server {
  listen 80 default_server;
  server_name www.server.com;
  root /var/www/html;

  location /foo/ {
      proxy_pass http://0.0.0.0:4000/;
      proxy_set_header Host $host;
  }

  location /bar/ {
      proxy_pass http://0.0.0.0:4001/;
      proxy_set_header Host $host;
  }
}

The apps are getting served up, but none of the links work. A link to the users#index action comes back as /users not /foo/users.

  • I've set config.relative_url_root in both apps, that helps with the assets but not the links.
  • I've tried with both the _url and _path methods, neither work.
  • This answer is close, but passenger_base_uri isn't a valid directive for stock nginx.
  • So then I followed the advanced configuration instructions for Passenger's nginx configuration and added passenger_base_uri = /foo; to my custom conf file and loaded it like so:

    passenger start -d -e production -p 4000 --nginx-config-template nginx.conf.erb

Still no love, and I'm out of ideas. Has anyone done this before? It seems like a common way to deploy multiple apps in production.

Daniel Knoppel

unread,
Jun 5, 2015, 5:41:51 AM6/5/15
to phusion-...@googlegroups.com
Just a wild guess, did you try the proxy line without the ending / ? Otherwise nginx will do rewriting on the url.

- Daniel

David Susco

unread,
Jun 5, 2015, 8:23:24 AM6/5/15
to phusion-...@googlegroups.com
Thanks, but I've tried that as well. It didn't make a difference.

David Susco

unread,
Jun 5, 2015, 11:20:07 AM6/5/15
to phusion-...@googlegroups.com

More Thoughts (2015-06-05)

Adding passenger_base_uri = '/foo' to my nginx.conf.erb file hosts the application in TWO locations (which is odd to me, but whatever):

  • localhost:4000/
  • localhost:4000/foo/

The first doesn't have the correct resource links (i.e. it's just '/users') but has access to its assets.

The second has the correct resource links (e.g. '/foo/users') but doesn't have its assets (this is because it's looking for /foo/assets/* inside of its public folder, not just /assets/*). I believe that this is the way to go though, as I can change my proxy like this to get at the application:

location /foo/ {
    proxy_pass http://0.0.0.0:4000/foo/;
    proxy_set_header Host $host;
}

Does anyone else have any thoughts though? If I do this, it'll mean I'll have to rake my assets intopublic/foo for it to work. Not the end of the world, but it still seems weird.

Reply all
Reply to author
Forward
0 new messages