How to generate a self-signed SSL certificate and use it in Nginx in docker-compose
While implementing barcode scanning using QuaggaJS, I realized that I have to have a secure origin in order for the live scanning feature to work on mobile devices. Exactly, as written in QuaggaJS README file:
The simplest thing to do for the development environment is to generate a self-signed certificate.
Generating self-signed certificate
Only one command is needed:
The command will prompt for the information to include in the certificate request. You can fill them as you wish,
only the Common Name (eg, fully qualified host name)
is required to generate the certificate.
Nginx config
The following should be in the nginx config:
Check the path for ssl_certificate
and ssl_certificate_key
in your configuration.
The suggested path works if the certificates directory is mounted to /etc/nginx/ssl
as described below in
docker-compose config.
Docker-compose config
In order for the certificate to work, add the following volume (assuming domain.crt
and domain.key
are located in
the certs
directory at the root of the project) to the nginx container:
And don’t forget to change the port: