Proxy requests to virtual host in by path prefix

非 Y 不嫁゛ 提交于 2019-12-06 09:38:52

问题


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>

回答1:


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


来源:https://stackoverflow.com/questions/20292781/proxy-requests-to-virtual-host-in-by-path-prefix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!