Reverse Proxy – Setting Up HTTPS Reverse Proxy on HTTP Jetty

jettyreverse-proxy

I have a jetty application on http.
My web hosting runs a reverse proxy on apache on https, which proxies to my jetty application (http).

browsing the first page (https://example.com/index.html) works,
however when I click on a link, it falls back to http. (http://example.com/link.html, instead of https://example.com/link.html)

how to solve this?
is it a configuration issue on apache (which should rewrite the urls), or is it a configuration in jetty (I should configure something such as the "canonical url" in jetty?)

actually I cannot change the configuration in apache (as only my webhosting provider has access to it), so I hope the issue can be solved on jetty. how to do so?
note: my jetty needs to run on http (not on https), as defined by my webhosting provider.

Best Answer

Try adding the following to your HTTP connector in the Jetty application:

<Set name="forwarded">true</Set>

This will try to read the following headers that are supposed to be sent by the proxy:

  • X-Forwarded-For - The IP address of the client
  • X-Forwarded-Host - The original host requested by the client in the Host HTTP request header
  • X-Forwarded-Server - The hostname of the proxy server
  • X-Forwarded-Proto - The URL protocol scheme of the original request

If Apache does not send these headers and your host cannot make it send these headers, you will probably need to write a custom Connector, you can read more about that here.