I have a Rails application (http://example.org) where multiple tenants can have a simple CMS. They get a frontend which resides at http://example.org/frontend/clients/:client_name
with relative sub-paths such as /posts
and /media
.
Now I wanted to allow tenants to use a custom domain, so the application will e.g. respond to a request to http://example.com/posts
with the contents of http://example.org/clients/example.com/posts
.
I managed to write an Nginx proxy_pass
rule to get that working [see below]. The problem is now that the relative Rails link helpers which are served on http://example.com/posts
(e.g. frontend_client_media_path
) still point to the paths defined in Rails, e.g. http://example.com/clients/example.com/media
.
Is there a possibility to tell Rails to construct the paths differently, by leaving out the /clients/example.com
part, as long as the site is accessed by a custom domain?
Appendix
Nginx-Rule (the meat of it)
server {
server_name _; # allow all domains
location / {
proxy_pass http://upstream/frontend/clients/$host$request_uri; # proxy to client-specific subfolder
}
}