Running Locally
Installing
> wget https://dl.eff.org/certbot-auto
> chmod a+x ./certbot-auto
> ./certbot-auto -n --install-only
Running certbot-auto to generate a certificate
> ./certbot-auto certonly
Installing with NGINX in a Docker Container
Build an image with certbot installed
> vi Dockerfile
FROM debian:buster # Installation de NGINX et dnsmasq RUN apt-get update RUN apt-get install nginx curl dnsmasq -y RUN apt-get install -y wget RUN apt-get install -y apache2-utils RUN apt-get install -y python-minimal # Création du dossier contenant les certificats RUN mkdir /etc/nginx/certificates # Volumes VOLUME /etc/nginx/sites-enabled VOLUME /etc/nginx/certificates # Copie des fichiers de configuration COPY confs/nginx.conf /etc/nginx/ COPY confs/proxy.conf /etc/nginx/conf.d/ RUN apt-get install -y certbot RUN apt-get install -y python-certbot-nginx # Exposition du port EXPOSE 80 443 # Add command CMD ["nginx", "-g", "daemon off;"] HEALTHCHECK CMD curl --fail http://localhost || exit 1
> docker build -t jmehan/nginx .
.
Create a container from the image
> vi buildDocker.sh
CONTAINER=proxy IMAGE=jmehan/nginx DIR=`pwd -P` docker stop $CONTAINER docker rm $CONTAINER #docker rmi $IMAGE docker run -d \ --net host \ --name $CONTAINER \ --restart=always \ -v $DIR/conf:/etc/nginx/sites-enabled \ -v $DIR/conf.d:/etc/nginx/conf.d \ -v $DIR/letsencrypt:/etc/letsencrypt \ --health-cmd='curl --fail https://wiki.jmehan.com || exit 1' \ $IMAGE docker logs -f $CONTAINER
> ./buildDocker.sh
View logs to see if our container started properly
> docker logs -f proxy
Execute certbot-auto to create our cert
> docker exec -it proxy /usr/bin/certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator nginx, Installer nginx Which names would you like to activate HTTPS for? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: creativeattitude.com ... ------------------------------------------------------------------------------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel):
Renewing Certificates
Script: renewAllCerts.sh
renewAllCerts.sh
#!/bin/bash set -e DOMAINS=( "bcs.jmehan.com" "www.jmehan.com" ) for d in ${DOMAINS[*]}; do echo "*** Renewing - $d" docker exec -it proxy /usr/bin/certbot --nginx -n -d $d done echo "**** ALL DONE *****"
References
Reference | URL |
---|---|
Getting Started | https://letsencrypt.org/getting-started/ |
*Using Certbot Auto | https://certbot.eff.org/docs/install.html#certbot-auto |
Certbot User Guide | https://certbot.eff.org/docs/using.html#certbot-commands |