apache 如何在 ProxyPass 中使用与 Tomcat 上下文名称不同的路径名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1393706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:09:01  来源:igfitidea点击:

How to use a different path name in ProxyPass than the Tomcat context name

apachetomcatmod-proxy

提问by Diptendu Dutta

I am using Tomcat 5.5.9 and Apache 2.x

我使用的是 Tomcat 5.5.9 和 Apache 2.x

We are trying to use a path name in ProxyPass that is different than the Tomcat context name.

我们试图在 ProxyPass 中使用与 Tomcat 上下文名称不同的路径名。

ProxyPass /path http://localhost:8080/contextname

However, this does not work. When these two are the same then everything works fine.

但是,这不起作用。当这两个相同时,一切正常。

Most examples I see on the net also have the path equal to the Tomcat context name.

我在网上看到的大多数示例的路径也等于 Tomcat 上下文名称。

I am using "context.xml" within the Tomcat context and do NOT have "server.xml" entries. Also, I am using plain httd.conf and NOT using any VirtualHost entries.

我在 Tomcat 上下文中使用“context.xml”并且没有“server.xml”条目。另外,我使用的是普通的 httd.conf 而不是使用任何 VirtualHost 条目。

Any help is appreciated.

任何帮助表示赞赏。

Regards,

问候,

Diptenu

双锥体

回答by David Rabinowitz

I believe you need both

我相信你两者都需要

ProxyPass /path/ http://localhost:8080/contextname/
ProxyPassReverse /path/ http://localhost:8080/contextname/

Any reason not to use mod_jk?

有什么理由不使用mod_jk吗?

回答by David Rabinowitz

RewriteEngine on
RewriteRule ^/path$ /path/ [R]
RewriteRule ^/path/(.*) /contextname/ [P]

ProxyPass /contextname/ protocol://192.168.15.48:8080/contextname/
ProxyPassReverse /contextname/ protocol://192.168.15.48:8080/contextname/

Where "protocol"="http" in this case...

在这种情况下,“协议”=“http”在哪里......

回答by Janning

Add a slash to both values:

为两个值添加斜杠:

ProxyPass /path/ http://localhost:8080/contextname/

ProxyPass /path/ http://localhost:8080/contextname/

回答by vasquez

Your problem are probably self-referential URLs that the application produces. There isn't much you can do about it except for

您的问题可能是应用程序生成的自引用 URL。除了

  1. changing the app or
  2. rewrite everything that it spits out.
  1. 更改应用程序或
  2. 重写它吐出的一切。

Option 2 can be very fragile. See the tomcat docsfor more info.

选项 2 可能非常脆弱。有关更多信息,请参阅tomcat 文档

回答by Kyle Dumas

Say your domain is bla.com and you want to proxy bla.com/path to 8080/contextname.

假设您的域是 bla.com,并且您想将 bla.com/path 代理到 8080/contextname。

If you use the following then you ultimately get a redirect to contextname

如果您使用以下内容,那么您最终会重定向到 contextname

ProxyPass /path http://localhost:8080/contextname
ProxyPassReverse /path http://localhost:8080/contextname

Result: bla.com/contextname (Redirect in the apache logs)

结果:bla.com/contextname(在 apache 日志中重定向)

In order to get your desired result you must include a slash after contextname.

为了获得您想要的结果,您必须在上下文名称后包含一个斜杠。

ProxyPass /path http://localhost:8080/contextname/
ProxyPassReverse /path http://localhost:8080/contextname/

Result: bla.com/path

结果:bla.com/path

A little late but this is where google takes you.

有点晚了,但这就是谷歌带你去的地方。