通过 apache mod_proxy 的码头

发布于 2024-09-16 15:07:30 字数 1217 浏览 1 评论 0原文

使用 Apache 虚拟主机和 mod_proxy 我想访问端口 8080 上的 jetty 实例中可用的 java 应用程序 (myapp)。

通过我的 apache 虚拟主机配置上的 ProxyPass / localhost:8080/ 我可以访问正在运行的应用程序在码头与 www.mydomain.com/myapp 但我希望从 www.mydomain.com 访问该应用程序。

尝试使用 ProxyPass / localhost:8080/myapp 找不到应用程序,因为请求变为 www.mydomain.com/myappmyapp/。

然后尝试:

<Location />
        ProxyPass localhost:8080/myapp/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
</Location>

我可以访问该应用程序,但仅限第一个请求。后续请求变成 www.mydomain.com/myappmyapp/

在阅读了多次 wiki.eclipse.org/Jetty/Tutorial/Apache 和 apache mod_proxy 文档后,我设法从 www.mydomain.com 正确使用该应用程序的唯一方法是使用以下配置:

<Location /myapp/>
        ProxyPass localhost:8080/myapp/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
</Location>

<Location />
        ProxyPass localhost:8080/myapp/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
</Location>

因此在这两种情况下请求都会转发到jetty应用程序。

我对 apache 和 jetty 很陌生,我很确定有更好、更优雅的方法来实现相同的结果。 事实上 apache 抱怨说:

[warn] worker localhost:8080/myapp/ already used by another worker

Using an Apache virtualhost and mod_proxy I want to access a java application (myapp) available in a jetty instance on port 8080.

With ProxyPass / localhost:8080/ on my apache virtualhost configuration I can access the application running in jetty with www.mydomain.com/myapp but I want the application to be accessed from www.mydomain.com.

Trying with ProxyPass / localhost:8080/myapp The application cannot be found because the request becomes www.mydomain.com/myappmyapp/.

Then tried with:

<Location />
        ProxyPass localhost:8080/myapp/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
</Location>

I can access the application but just for the first request. Subsequent requests become www.mydomain.com/myappmyapp/

After reading many times wiki.eclipse.org/Jetty/Tutorial/Apache and the apache mod_proxy docs the only way I managed to use the application properly from www.mydomain.com is with the following configuration:

<Location /myapp/>
        ProxyPass localhost:8080/myapp/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
</Location>

<Location />
        ProxyPass localhost:8080/myapp/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
</Location>

so the request is forwarded to the jetty application in both cases.

I am quite new to apache and jetty and I am pretty sure there is a better and more elegant way of achieving the same result.
In fact apache complains saying:

[warn] worker localhost:8080/myapp/ already used by another worker

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

软的没边 2024-09-23 15:07:31

问题是,当您使用上下文路径 /myapp 在 jetty 中部署应用程序时,它将相应地生成所有链接。 Apache mod_proxy 在 HTTP 级别(标头)进行所有重写,并且不会对响应正文执行任何操作,保持原样。

如果您不介意 /myapp 留下来,您可以打开 mod_rewrite 并在您的位置块中包含以下两行:

RewriteEngine on
RewriteRule ^/myapp/(.*)$ /$1 [P]

如果您想永久摆脱 /myapp,那么剩下的唯一选择(假设您不这样做)不想在 mod_proxy_html 上浪费 CPU 资源)的方法是配置虚拟主机,并在上下文路径为 / 的虚拟主机上部署应用程序。

The problem is that when you deploy your application in jetty with the context path /myapp, it will generate all links accordingly. Apache mod_proxy does all the rewriting at the HTTP level (headers) and won't do anything with the response body, keeping it as it is.

If you don't mind the /myapp sticking around, you can turn mod_rewrite on and include following two lines in your Location block:

RewriteEngine on
RewriteRule ^/myapp/(.*)$ /$1 [P]

If you would like to get rid of /myapp for good, then the only option left (assuming you don't want to waste CPU power on mod_proxy_html) is to configure virtual hosts, and deploy applications on virtual hosts with context path of /.

澜川若宁 2024-09-23 15:07:31

如果您希望可以在站点的根目录访问您的 Web 应用程序,则需要将 Web 应用程序部署到容器的根目录中。通常,这是通过调用 war 文件 ROOT.war 而不是 myapp.war 来完成的(尽管这最终取决于 Jetty 的配置)部署程序,这可能比默认的更复杂)。

If you want your webapp to be accessible at the root of your site, what you need is to deploy the web application into the root of container. Usually, this is done by calling the war file ROOT.war instead of myapp.war (although this ultimately depend on the configuration of your Jetty deployer, which may be more complex than the default).

叫思念不要吵 2024-09-23 15:07:31

是的,它可以从码头根运行,但我希望运行多个应用程序。 myapp 的配置位于 jetty 的 contexts 文件夹下:

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
  <Set name="contextPath">/mvc-showcase</Set>
  <Set name="war"><SystemProperty name="jetty.home"/>/webapps/mvc-showcase.war</Set>
</Configure>

我的 jetty 版本是 6.1.22

Yes it works from the jetty root, but I would like to have more than one application running. The configuration for myapp is under jetty's contexts folder:

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
  <Set name="contextPath">/mvc-showcase</Set>
  <Set name="war"><SystemProperty name="jetty.home"/>/webapps/mvc-showcase.war</Set>
</Configure>

my jetty version is 6.1.22

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文