DEV Community

Cover image for HTTPS on Localhost for Any Web Application
Artem
Artem

Posted on

HTTPS on Localhost for Any Web Application

Having a TLS certificate is not a common requirement for local development. Moreover, many tools, like Angular or Parcel allow you to seamlessly generate certs with a runtime options. That said, sometimes you might need to serve HTTPS traffic to an application that doesn't support TLS certificates auto-generation. In this cases, there is no elegant workaround, rather than actually generate the certificates manually. It can be done using tools, like openssl, and there is a number of great how-to articles on the topic, for example this one.

One-Command TLS with Caddy

Caddy is a web server written in go that among other features automates TLS certificates generation. All you need for Caddy to proxy traffic to your app is one simple command:

# considering the app is running on port 3000
caddy reverse-proxy --to http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

For more complex usecases, Caddy also has a notion of Caddyfile, which is the same as configuration file.

Installation

For the install process, refer to the Download section of the Caddy docs.

Depending on preferred method of your installation, you might need to make your system trust the TLS certificates Caddy generates.

# adds certs into the local trust store
caddy trust
Enter fullscreen mode Exit fullscreen mode

Google Chrome Issue Fix

Up until Caddy's recent release, there is a know issue affecting Google Chrome browsers (or other Chrome-based).

Alt Text

In case you see the warning from above, please check that you have the latest version of Caddy installed!

Top comments (0)