Elastic Beanstalk HTTPS redirection when using TCP ports

Ross Harrison
The Startup
Published in
1 min readMay 24, 2019

[Link to the solution gist]

I’m deploying an application to a Docker environment within Elastic Beanstalk. The application serves HTTP and Web Socket requests over the HTTP(s) port.

AWS provides a configuration that works when forwarding HTTP to HTTPS. However, in order to serve web socket requests, I needed to forward SSL to TCP in the load balancer configuration.

Forwarding to TCP for Websockets

When using the provided configuration https and https request would get redirect to https. This lead to an infinite loop. The snippet below was the cause.

The protocol being forwarded was not https, so a redirect would be returned until the browser stopped following them. I adjusted the configuration to look for positive matches specific request protocols.

The logic may look a little strange, but nginx doesn’t allow for compound Boolean logic. Essentially ws is redirected to wssand http is redirected to https unless the request is a health check.

[Link to the solution gist]

--

--