我正在使用nginx为两个 Rails 站点提供服务。Rails1 不使用资产管道,但 Rails2 使用。Rails2 也使用前缀来区别于 Rails1。例如:
http://myhost -> Rails1 http://myhost/abc -> Rails2
两个站点都在运行,但是没有找到对 Rails2 站点上资产的任何引用。
这是我的伪 nginx.conf 的样子:
http {
上游轨道1 {
服务器 127.0.0.1:3000;
}
上游轨道2 {
服务器 127.0.0.1:3030;
}
服务器 {
位置 ~ ^/assets/ {
最大过期;
add_header 缓存控制公共;
access_log 关闭;
}
位置 /abc {
proxy_pass http://rails2;
}
地点 / {
proxy_pass http://rails1;
}
}
}
此外,我的 Rails 2 应用程序中的 routes.rb :
Rails2App::Application.routes.draw do
scope '/abc' do
resources :projects
root :to => 'home#index'
end
end
浏览到http://myhost/abc/Rails2 应用程序,打开没有 css 的页面,并出现以下错误:
获取 http://myhost/assets/application-asdasd.css 404(未找到)
我试过config.assets.prefix = '/abc'在 production.rb 文件中使用,但没有用。我还尝试了 ngnix.conf 文件中的不同变体,但也无济于事。
任何人都知道我做错了什么或错过了什么?
更新
我不太清楚为什么,但我能够使用@location 而不是上游来(错误地)工作。但我不得不将资产文件夹从 Rails2 应用程序移动到 Rails1 应用程序。不完全理想。
对服务器部分的更改:
位置〜^/(资产)/ {
最大过期;
add_header 缓存控制公共;
access_log 关闭;
}
位置 ~ ^/(abc)/ {
根 /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;
}
地点 / {
根 /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;
}
位置@rails1 {
proxy_pass http://127.0.0.1:3000;
}
位置@rails2 {
proxy_pass http://127.0.0.1:3030;
}