liveBook · Manning

Self-signed certificate

As explained in Learn Docker in a Month of Lunches, Second Edition

A self-signed certificate is a digital certificate whose signature is produced by the same entity identified by the certificate.

A self-signed certificate lets a nonproduction HTTPS site use SSL without obtaining a certificate from a domain provider or Let’s Encrypt. Nginx can terminate SSL centrally instead of requiring certificates in every application container. section 20.2

Create and use one for a local image-gallery site:

  • Generate the certificate and key with an OpenSSL-based container, mounting the output into a local certificates directory. section 20.2
  • Mount the certificates into Nginx and enable a site configuration that listens on port 443. section 20.2
  • Redirect port 80 requests to HTTPS with an HTTP 301 response, then reload Nginx. section 20.2

Local HTTPS warning

Opening image-gallery.local over HTTPS produces a browser warning because the certificate is not trusted. For a development site, proceed through the browser’s advanced option; use trusted certificates in production. section 20.2

# generate a self-signed certificate - Linux containers:
docker container run -v "$(pwd)/nginx/certs:/certs" `
 -e HOST_NAME=image-gallery.local diamol/cert-generator:2e
# OR Windows Server containers:
docker container run -v "$(pwd)/nginx/certs:C:\certs" `
 -e HOST_NAME=image-gallery.Local diamol/cert-generator:2e
# remove the existing image-gallery configuration:
rm ./nginx/sites-enabled/image-gallery.local
# copy in the new site configuration with SSL:
cp ./nginx/sites-available/image-gallery-3.local `
 ./nginx/sites-enabled/image-gallery.local
# and restart nginx:
docker exec nginx-nginx-1 nginx -s reload
# browse to http:/./image-gallery.local

Run the certificate generator, install the SSL-enabled Nginx configuration, reload Nginx, and test the local site. section 20.2

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains generation, mounting, redirecting, and reloading, but defers detailed protocol and cipher configuration.
Examples
Uses a Dockerized image-gallery site, OpenSSL-generated files, Nginx configuration, HTTP redirects, and a Firefox warning.
What it assumes
Assumes basic Docker and Nginx usage while demonstrating the certificate-generation workflow directly.
What you can do after
Operate/configure a local HTTPS site by generating certificates and wiring them into Nginx.
How it connects
Connects HTTPS, SSL termination, Nginx, reverse proxies, OpenSSL, TLS, and browser trust warnings.

Also explained in

Compare how 4 books explain self-signed certificate →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.