Spring Boot: Caddy as a reverse proxy for my app

Tue, Jun 9, 2020 2-minute read

We used to work with HAproxy as a reverse proxy for our solutions for a long time. Recently we switched to Caddy, and post is rather reminder to myself. Caddy is, using its own words, “HTTP/2 web server with automatic HTTPS.” Caddy is really the web server, but also contains many modules for very specific usage. And one of these is ‘proxy module’ … that states as a reverse proxy for other solutions.

Caddy

We usually run our SpringBoot apps under Apache Tomcat deployed as war archives. We can expose Tomcat directly to internet or run it behind reverse proxy. And this is what we use Caddy for.

There are many reverse proxy solutions — why Caddy?

  • Caddy is created with Go lang and as such, we have a binaries for many plaforms … Windows included (our solution stack currently supports CentOS and Windows)

  • Caddy is very easy to configure. To run it as a reverse proxy for our Tomcat server we make this simple configuration.

    Caddy

  • It just says … run my web on HTTPS, send all requests to my 192.168.2.30:8080 backend, send header forward info (e.g. X-Forwarded-For) and forward websocket communication too. Easy as this.

  • Did you just notice this small ‘https’ in URL? It says to Caddy that we want to run HTTPS service only. But where is SSL certificate configuration? And this is really, really nice!!! If we don’t specify SSL certificate info, Caddy automaticly creates one using Let’s Encrypt service, install it and run server(reverse proxy) with it. All these without any other manual configuration. What’s more, Caddy monitors SSL certificate expiracy and renew it automaticly when necessary.

  • Must say it once again here … Caddy manages SSL certificates automaticly for free! Just imagine we run many different web sites under SSL. Caddy manages all of them. And because its a reverse proxy ‘only‘, we can make Caddy to be a SSL frontend for many different internal systems.

  • Caddy is available for free! Really — you can download it here https://github.com/mholt/caddy/releases or build yourself … its quite easy with Go lang … for any platform.

  • Kudos to author. Give him a start on github :-)

Just don’t forget we started with SpringBoot app. To allow our app to identify URL correctly, we should add following lines to application.properties file in our project. Details can be found in docs here.

Caddy