ruby-on-railsapachetorquebox

Proxy requests to virtual host in by path prefix


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>

Solution

  • 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