2

I'm running multiple Rails applications on TorqueBox. Each application is mounted on a different web context, e.g., localhost:8080/app1 and localhost:8080/app2 (configured via TorqueBox). Apache is configured to accept requests to app1.domain.com and app2.domain.com via virtual hosts. However, I'm running into problems where some application paths (form submission paths and others) expect to be preceeded by /app1, e.g., http://app1.domain.com/app1/rest/of/path instead of the correct http://app1.domain.com/rest/of/path.

How can I configure Apache so that the requests to http://app1.domain.com/app1/... are made to the correct path (i.e., without the leading /app1)? I've tried doing this with redirects but that doesn't work since they force a GET request and the POST data is lost in the process.

This is my current Apache config:

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
ProxyRequests Off
ProxyPreserveHost On
NameVirtualHost *:80

<VirtualHost *:80>  # There are multiple vhosts like this one, for different apps.
    ServerName app1.domain.com
    ProxyPass / http://127.0.0.1:8080/app1/
    ProxyPassReverse / http://127.0.0.1:8080/app1/
</VirtualHost>
Haukur
  • 151
  • 1
  • 9
  • I got the same problem but with nginx. Have you found a solution yet? – raskhadafi Jan 04 '14 at 22:03
  • 2
    Try setting the host instead of the context in the TorqueBox configuaration. For example, instead of using context '/sub1', use host 'sub1.domain.tld'. Then everything should work fine. See this: http://torquebox.org/documentation/3.0.1/deployment-descriptors.html#ruby-descriptor-layout I hope it helps. – Haukur Jan 05 '14 at 04:34
  • Thanks for the hint! Now I'm stuck within the nginx configuration! – raskhadafi Jan 05 '14 at 13:08

1 Answers1

2

I solved this problem by using a web host instead of a web context in the TorqueBox configuration. After that, getting the Apache configuration to work was no problem since different apps were not under specific context paths.

So, instead of this (in config/torquebox.rb):

TorqueBox.configure do
  web do
    context '/app1' 
  end
end

You should do this:

TorqueBox.configure do
  web do
    host 'app1.domain.tld'
  end
end
Haukur
  • 151
  • 1
  • 9
  • On TorqueBox 3.1 I'm having seemingly [the same issue](http://stackoverflow.com/questions/20292781/proxy-requests-to-virtual-host-in-by-path-prefix), and even have the same config, but unfortunately in my case I have found no working solution. Any thoughts? – ylluminate Jun 15 '14 at 01:07
  • Got it clarified and [put a more detailed response in my thread as noted](http://stackoverflow.com/a/24245931/320681). – ylluminate Jun 16 '14 at 14:32