通过 apache mod_proxy 的码头
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是,当您使用上下文路径 /myapp 在 jetty 中部署应用程序时,它将相应地生成所有链接。 Apache mod_proxy 在 HTTP 级别(标头)进行所有重写,并且不会对响应正文执行任何操作,保持原样。
如果您不介意 /myapp 留下来,您可以打开 mod_rewrite 并在您的位置块中包含以下两行:
如果您想永久摆脱 /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:
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 /.
如果您希望可以在站点的根目录访问您的 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 ofmyapp.war
(although this ultimately depend on the configuration of your Jetty deployer, which may be more complex than the default).是的,它可以从码头根运行,但我希望运行多个应用程序。 myapp 的配置位于 jetty 的 contexts 文件夹下:
我的 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:
my jetty version is 6.1.22