Rails app served via Passenger standalone behind an nginx proxy -
i have 2 apps: /foo , /bar. in each of folders i'm starting passenger. foo:
passenger start -d -e production -p 4000 and bar:
passenger start -d -e production -p 4001 i have nginx configured 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 getting served up, none of links work. link users#index action comes '/users' not '/foo/users'.
- i've set config.relative_url_root in both apps, helps assets not links.
- i've tried both
_url,_pathmethods, neither work. - this answer close, passenger_base_uri isn't valid directive stock nginx.
so followed advanced configuration instructions passenger's nginx configuration , added
passenger_base_uri = '/foo';custom conf file , loaded so:passenger start -d -e production -p 4000 --nginx-config-template nginx.conf.erb
still no love, , i'm out of ideas. has done before? seems common way deploy multiple apps in production.
more thoughts (2015-06-05)
adding passenger_base_uri = '/foo' nginx.conf.erb file hosts application in 2 locations (which odd me, whatever):
localhost:4000/localhost:4000/foo/
the first doesn't have correct resource links (i.e. it's '/users') has access assets.
the second has correct resource links (e.g. '/foo/users') doesn't have assets (this because it's looking /foo/assets/* inside of public folder, not /assets/*). believe way go though, can change proxy @ application:
location /foo/ { proxy_pass http://0.0.0.0:4000/foo/; proxy_set_header host $host; } does else have thoughts though? if this, it'll mean i'll have rake assets public/foo work. not end of world, still seems weird.
for else looking same thing, here's in end:
- follow advanced configuration project specific nginx.conf.erb file.
- add passenger_base_uri directive file app (e.g.
passenger_base_uri = '/foo';) - in config/environments/production.rb file move location of assets:
config.assets.prefix = '/foo/assets'. - start passenger
passenger start -d -e production -p some_port --nginx-config-template nginx.conf.erb in nginx proxy configuration add location directive app:
location /foo/ { proxy_pass http://0.0.0.0:some_port/foo/; proxy_buffering off; proxy_http_version 1.1; proxy_set_header connection $connection_upgrade; proxy_set_header host $host; # more robust http_host proxy_set_header upgrade $http_upgrade; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; # ensures app's env correct proxy_set_header x-forwarded-host $host; # proxy_set_header x-forwarded-proto https; # add if want redirects go https }
after that, (re)start nginx proxy , should @ http://your_proxy/foo/.
Comments
Post a Comment