我有一個Rails應用程序(http://example.org),其中多個租戶可以有一個簡單的CMS。他們得到一個前端,其位於http://example.org/frontend/clients/:client_name
,相關的子路徑如/posts
和/media
。在Nginx反向代理後面更改應用程序的Rails鏈接路徑
現在我想允許租戶使用自定義域,因此應用程序將例如對http://example.com/posts
的請求做出迴應,內容爲http://example.org/clients/example.com/posts
。
我設法寫一個Nginx的proxy_pass
規則來獲得工作[見下文]。現在的問題是,在http://example.com/posts
(例如frontend_client_media_path
)上服務的相對Rails鏈接助手仍然指向Rails中定義的路徑,例如, http://example.com/clients/example.com/media
。
只要站點被自定義域訪問,是否有可能通過忽略/clients/example.com
部分來告訴Rails以不同方式構建路徑?
附錄
Nginx的規則(它的肉)
server {
server_name _; # allow all domains
location/{
proxy_pass http://upstream/frontend/clients/$host$request_uri; # proxy to client-specific subfolder
}
}