Install/SSL via Let's Encrypt
Jump to navigation
Jump to search
This is still in draft!!
There are these steps involved. And the best thing about it is: It cost nothing :)
- Have Let's Encrypt create a certificate, download it to your Server (Virtual Private Server, Dedicated Server, Raspberry PI - what ever you have accessible from the internet)
- Have your web-service use the certificate (Apache, Nginx - or whatever receives web traffic. Service typically document how to do this)
- Setup automatic certificate renewal (Replacing the certificate within 2 to 3 month is good practice. Automating it makes it painless)
Create a Certificate
Get certbot on you Server. (See also https://github.com/certbot/certbot )
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
sudo mv certbot-auto /usr/local/bin/
# verify that the command can be run without issues
certbot-auto --help
sudo certbot-auto certonly --webroot -w <path to virtual host web root> -d <domain.com> -d <www.domain.com>
Use the Certificate
Nginx
Edit your nginx config, typically in /etc/nginx/sites-enabled/default
nano /etc/nginx/sites-enabled/default
Edit the port 80 section for http traffic:
server {
# This allows Let's Encrypt CA to exchange information via your virtual host's domain name
location ~ /.well-known {
allow all;
}
# If you want to redirect all non-https request to HTTPS URL
if ($request_uri !~ "^/\.well\-known")
{
rewrite ^(.*)$ https://$host$1 permanent;
}
# the lines below come from default Nginx config file
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
...
}
Also edit the port 443 section for https traffic:
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/<domain.com>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<domain.com>/privkey.pem;
include /etc/nginx/include/diffie-hellman;
root <virtual host web root>;
# Make site accessible from domain.com and www.domain.com
server_name www.<domain.com> <domain.com>;
}
Setup Automatic Certificate Renewal
sudo crontab -e
Add this. It'll renew the certificate and reload nginx so it will use them:
# You may want to setup logrotate to rotate the log file 0 1 * * * certbot-auto renew >> /var/log/letsencrypt-renewal.log 0 2 * * 1 service nginx reload