Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] How to use Jetty ProxyServlet for reverse proxying?

Hi,

On Fri, Aug 27, 2021 at 6:24 PM Peter Boughton <jetty@xxxxxxxxxxxxxxxxx> wrote:
>
> Hello,
>
> I need to setup Jetty 9.4 as a HTTP reverse proxy, but the Jetty docs
> for ProxyServlet do not contain an example (or even any useful hints):
>
> http://www.eclipse.org/jetty/documentation/jetty-9/index.html#proxy-servlet
>
> I found an example by Joakim on Stack Overflow, but it isn't working.
>
> https://stackoverflow.com/questions/52557018/jetty-9-x-proxyservlet-how-to-set-up-servletcontext-correctly-in-xml/52597488#52597488
>
> I've tested with both Java 8 and Java 11 on Debian and Windows.
>
> Using Jetty 9.4.43 rather than the 9.4.14 the example used, but I
> wouldn't expect that to be a problem?
>
> $ mkdir proxy-test
> $ cd proxy-test
> $ java -jar ../jetty-distribution-9.4.43.v20210629/start.jar
> --add-to-start=http,deploy,proxy
> $ java -jar ../jetty-distribution-9.4.43.v20210629/start.jar
>
> Before creating the webapp, accessing localhost:8080 would usually give
> an unknown context error, but instead it gives the following:
>
> HTTP ERROR 502 Bad Gateway
> URI:    /
> STATUS: 502
> MESSAGE:        Bad Gateway
> SERVLET:        org.eclipse.jetty.proxy.ProxyServlet-7e0b0338

Please file an issue about this.

I checked and the module as it is is not usable out of the box.
What happens is that because there is no URL rewriting, the
ProxyServlet will proxy to itself in a loop until the proxied headers
become too large and an error is reported, which results in the 502.

Ideally, you would use this module and specify a "proxyTo" pointing to
a backend server, but as I said, this is currently not implemented.

What is your exact use case? Would the above be enough for you?

--
Simone Bordet
---
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz


Back to the top