DEV Community

Cover image for HTTPS on localhost using mkcert
👨‍💻Ioannis Diamantidis
👨‍💻Ioannis Diamantidis

Posted on • Originally published at diamantidis.github.io

HTTPS on localhost using mkcert

When working on a website or a service, the development environment should imitate as much as possible the production one. And since most production websites and services are served on HTTPS, the same should happen for the development versions as well. This is exactly what mkcert is trying to solve.

mkcert is a tool that makes it easy to generate locally-trusted SSL certificates signed by a local CA (Certificate Authority).

On macOS, you can use Homebrew to install the tool:

# Install on macOS
brew install mkcert
# Generate and install a local CA
mkcert -install
# Create a new certificate
mkcert -key-file key.pem -cert-file cert.pem localhost
Enter fullscreen mode Exit fullscreen mode

Now you can use the SSL key and cert for your local server. For instance, if you have a Jekyll blog, you can use the following command to serve on HTTPS

jekyll server --ssl-cert ./cert.pem --ssl-key ./key.pem
Enter fullscreen mode Exit fullscreen mode

Now, you can browse your local Jekyll site on https://localhost:4000! 🎉


➡️ This post was originally published on my blog.

Photo by Tobias Giess on Unsplash

Latest comments (0)