Configuring embedded Jetty 9 for X-FORWARDED-PROTO with Spring Boot


I am running a Spring Boot application in AWS. The application is running behind an Elastic Load Balancer (ELB). The ELB is configured to use https (port 443) to the outside world, but passes through http (port 8080) to the application. The ELB is configured to pass through the x-forwarded-proto header. I am using Jetty 9.0.0.M0, with Spring Boot 1.1.5 RELEASE.

I appear to be getting incorrect redirects sent back from the application via the ELB where the redirect responses are coming back as http, rather than https. Now, I read here that I should set the “forwarded” header to true using:

I can’t see how to do this with the embedded version of Jetty in Spring Boot because there is no XML configuration file as part of my source.

I have looked at the EmbeddedServletContainerCustomizer infrastructure but I still can’t get the right incantation to get this setup to work.

The application is built and tested outside of the AWS https environment, so the application needs to transparently work with http too. Directly hitting the application endpoints without going through the ELB works. It’s just that the ELB to application route that’s not working.

Any ideas?


Had a similar issue myself and while researching stumbled across your question. I found this was quite easy to to programatically however isn’t really explained in the Jetty docs.

The structure of the Jetty xml configuration files are matched by the structure of the java API so you can just replicate it in code.

So following the Jetty guide on how to configure using the XML configuration file here

I was able to configure the embedded server programatically like this:

Leave a Reply