NGINX with Self-Signed Certificate on Docker

While working with our code, we often need to quickly check if something works under HTTPS — or more importantly, how it behaves under HTTPS. There are plenty of guides online showing you how to create a Certificate Sign Request (CSR), how to self-sign that CSR, and how to manually modify your web server’s configuration to make it use that certificate.

In this article, I will present a fully-automated process using Docker to quickly spin up an NGINX container with a self-signed certificate — all without having to generate or manually edit anything at all!

Security note and warning

  1. A self-signed certificate can only be trusted by… you. It is not a means to serve data in a production environment; use a proper certificate in such cases.
  2. The NGINX configuration to serve content under HTTPS presented in this article is the bare minimum to get the job done. If you want to modify a production NGINX with TLS, please consult the official guide.

If you are just starting with Public Key Cryptography, I have written an introduction article you might find useful.

Click Here