I'm serving two Rails sites using nginx. Rails1 does not use the asset pipeline but Rails2 does. Rails2 also uses a prefix to differentiate it from Rails1. For example:
http://myhost -> Rails1 http://myhost/abc -> Rails2
Both sites are running, however any reference to assets on the Rails2 site are not found.
Here's what my pseudo nginx.conf looks like:
http { upstream rails1 { server 127.0.0.1:3000; } upstream rails2 { server 127.0.0.1:3030; } server { location ~ ^/assets/ { expires max; add_header Cache-Control public; access_log off; } location /abc { proxy_pass http://rails2; } location / { proxy_pass http://rails1; } } }
Also, the routes.rb in my Rails 2 app:
Rails2App::Application.routes.draw do
scope '/abc' do
resources :projects
root :to => 'home#index'
end
end
Browsing to http://myhost/abc/
for the Rails2 app, brings up the page with no css, and the following error:
GET http://myhost/assets/application-asdasd.css 404 (Not Found)
I've tried using config.assets.prefix = '/abc'
in the production.rb file but it didn't work. I've also tried different variations in the ngnix.conf file to no avail either.
Anyone know what I'm doing wrong, or missing?
UPDATE
I'm not quite sure why, but I was able to get this to (incorrectly) work using an @location instead of an upstream. But I had to move the assets folder from the Rails2 app to the Rails1 app. Not exactly ideal.
Changes to the server section:
location ~ ^/(assets)/ { expires max; add_header Cache-Control public; access_log off; } location ~ ^/(abc)/ { root /rails2/public; try_files $uri/index.html $uri.html $uri @rails2; error_page 404 /404.html; error_page 422 /422.html; error_page 500 502 503 504 /500.html; error_page 403 /403.html; } location / { root /rails1/public; try_files $uri/index.html $uri.html $uri @rails1; error_page 404 /404.html; error_page 422 /422.html; error_page 500 502 503 504 /500.html; error_page 403 /403.html; } location @rails1 { proxy_pass http://127.0.0.1:3000; } location @rails2 { proxy_pass http://127.0.0.1:3030; }