Let's encrypt with Nginx
In this article, I will share the way of using nginx, let’s encrypt and docker/docker-compose to deploy ssl with automatically cert-renew.
Last updated
In this article, I will share the way of using nginx, let’s encrypt and docker/docker-compose to deploy ssl with automatically cert-renew.
Last updated
is a web server that I used to replace . Since I have to deploy my application which will provide SSL connection through the internet, I utilize Let’s Encrypt, a that provides free for (TLS) encryption.
Apart from that, docker and docker-compose will be used to setup my environment which is really really convenient tools for deployment. I guess you should already know what this items are so I am not going to explain how to use these tools here.
Given the directory structure like this:
Create a docker-compose.yml file under root directory.
Create and configure Nginx configure in cond.d directory.
You can apply proxy_pass in location if you need.
normal.conf
ssl.conf
Navigate to the root directory and run the following command to sign the certificate from Let’s Encrypt.
Note! You have to use full path in Volume Mirror
If you want to automatically renew the cert, you can use crontab to do the schedule job. You can use contab -e
to do the job but this will only apply in the user-level. I would recommend you to do this in system-level — edit the config directly in /etc/crontab
.
You can use following script to schedule the task. it will run every 15 days.
Note! Cert can only be renewed within last 30 days.
這個『 crontab -e 』是針對使用者的 cron 來設計的,如果是『系統的例行性任務』時, 該怎麼辦呢?是否還是需要以 crontab -e 來管理你的例行性工作排程呢?當然不需要,你只要編輯 /etc/crontab 這個檔案就可以啦!有一點需要特別注意喔!那就是 crontab -e 這個 crontab 其實是 /usr/bin/crontab 這個執行檔,但是 /etc/crontab 可是一個『純文字檔』喔!你可以 root 的身份編輯一下這個檔案哩! -
The renew command will take a look at all active certificates and renew those who are close to expiring — which is currently defined as 30 days before the expiration date. If your certificates aren’t due for renewal yet, the client won’t renew them. The reason why a daily cronjob is recommended is in order to avoid issues caused by service downtime on Let’s Encrypt’s end, or any issues your server might have. If you, for example, run the cronjob just once every month or every two months, and the service just happens to be down during those times, you’ll end up with an expired certificate eventually. By doing it daily instead, Let’s Encrypt would have to be down for 30 consecutive days for that to happen, which is rather unlikely. -