本文介绍了代理请求到虚拟主机由路径preFIX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上运行多个TorqueBox Rails应用程序。每个应用程序安装在不同的网络环境,例如,本地主机:8080 / APP1 本地主机:8080 / APP2 (通过TorqueBox配置)。 Apache的配置为接受通过虚拟主机的请求 app1.domain.com app2.domain.com 。不过,我运行到哪里了一些应用程序路径(表单提交路径等)预期由 / APP1 pceeded $ P $,例如, http://app1.domain.com/app1/rest/of/path 而不是正确的 http://app1.domain.com/rest/of/path

如何配置Apache这样的请求 HTTP://app1.domain.com/app1 / ... 都是正确的路径做出(即没有前导 / APP1 )?我试着重定向这样做,但是,这并不工作,因为他们强制GET请求和POST数据的过程中丢失。

这是我目前的Apache配置:

 的LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
的LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
将ProxyRequests关闭
代理preserveHost在
*了NameVirtualHost:80<虚拟主机*:80> #有多个虚拟主机像这样的,对于不同的应用程序。
    服务器名app1.domain.com
    的ProxyPass / http://127.0.0.1:8080/app1/
    ProxyPassReverse / http://127.0.0.1:8080/app1/
< /虚拟主机>


解决方案

我用一个虚拟主机,而不是在TorqueBox配置web环境解决了这个问题。在此之后,得到了Apache的配置工作是没有问题的,因为不同的应用程序并没有受到特定的上下文路径。

因此​​,代替(在配置/ torquebox.rb )的这样的:

  TorqueBox.configure做
  做网站
    上下文/ APP1
  结束
结束

您应该这样做:

  TorqueBox.configure做
  做网站
    举办​​app1.domain.tld
  结束
结束

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>
解决方案

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

这篇关于代理请求到虚拟主机由路径preFIX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 02:18