...
> vi Dockerfile
Code Block |
---|
FROM lerenn/nginx-reverse-proxy 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 wget https://dl.eff.org/certbot-auto RUN chmod +x certbot-auto RUN ./certbot-auto -n --install-only |
> docker build -t ca/nginx .
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
...
Code Block |
---|
CONTAINER=proxy IMAGE=cajmehan/nginx DIR=`pwd -P` docker stop $CONTAINER docker rm $CONTAINER #docker rmi $IMAGE docker run -d \ --net host \ --name $CONTAINER \ --restart=always \ -pv 80:80 \ --name $CONTAINER$DIR/conf:/etc/nginx/sites-enabled \ -v $PWD$DIR/conf.d:/etc/nginx/sites-enabledconf.d \ -v $PWD$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
...
Execute certbot-auto to create our cert
> docker > docker exec -it proxy ./usr/bin/certbot --autonginx
Code Block |
---|
Saving debug log to /var/log/letsencrypt/letsencrypt.log Failed to find executable apache2ctl in PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin Plugins selected: Authenticator nginx, Installer nginx Which names would you like to activate HTTPS for? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: creativeattitude.com ... ---------------------------------------- 1: creativeattitude.com 2: www.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): 1 Obtaining a new certificate Performing the following challenges: http-01 challenge for creativeattitude.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/creativeattitude.conf Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. ------------------------------------------------------------------------------- 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. ------------------------------------------------------------------------------- Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1 ------------------------------------------------------------------------------- Congratulations! You have successfully enabled https://creativeattitude.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=creativeattitude.com ------------------------------------------------------------------------------- IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/creativeattitude.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/creativeattitude.com/privkey.pem Your cert will expire on 2018-07-22. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le |
Renewing Certificates
Script: renewAllCerts.sh
Code Block | ||||
---|---|---|---|---|
| ||||
#!/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 |
...