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?

I have tried with Jetty v9.4.12 and it still has the problem, so have to assume I'm doing something wrong since the Stack Overflow answer is marked as accepted and was written against that version.

I have tried with both the media-proxy.xml example previously linked, and with what I think is the simplest possible definition - a ROOT.xml with a Transparent Proxy Servlet and single proxyTo argument.

Since it's not working, there must be something incorrect or missing in the following - can anyone identify what it is?


mkdir test-jetty-proxy
cd test-jetty-proxy
curl -O https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/9.4.12.v20180830/jetty-home-9.4.12.v20180830.zip
unzip jetty-home-9.4.12.v20180830.zip
JETTY_HOME=../jetty-home-9.4.12.v20180830

mkdir test-target
cd test-target
java -jar $JETTY_HOME/start.jar --add-to-start=http,deploy
echo 'jetty.http.port=8081' >> 'start.ini'
mkdir -p webapps/ROOT
echo 'TEST' > webapps/ROOT/index.html
java -jar $JETTY_HOME/start.jar &
sleep 5
curl -isS 'http://localhost:8081/'
cd ..

mkdir test-proxy
cd test-proxy
java -jar $JETTY_HOME/start.jar --add-to-start=http,deploy,proxy
mkdir webapps

echo '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd";>
<Configure class="org.eclipse.jetty.servlet.ServletContextHandler">
<Call name="addServlet">
<Arg>org.eclipse.jetty.proxy.ProxyServlet$Transparent.class</Arg>
<Arg>/*</Arg>
<Call name="setInitParameter">
<Arg>proxyTo</Arg>
<Arg>http://localhost:8081/</Arg>
</Call>
</Call>
</Configure>' > webapps/ROOT.xml

java -jar $JETTY_HOME/start.jar &
sleep 5
curl -isS 'http://localhost:8080/'

# should return index.html from test-target, but gives 502 Bad Gateway instead.

# use "kill %1 %2" to shutdown both servers


Back to the top