2016.09.04

  1. Install the Let’s Encrypt client
  2. Get the Let’s Encrypt certificate
  3. Generate diffie-Hellman Group(Optional)
  4. Modify the nginx configuration
  5. Example Set automatic certificate update
Install the Let’s Encrypt client
sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencryptCopy the code

Get the Let’s Encrypt certificate

You must first close the program that occupies port 80

sudo ./letsencrypt-auto certonly --standaloneCopy the code

Enter the domain name to generate the certificate:

Please enter in your domain name(s) (comma and/or space separated)
------------------------------------------------------------------
|                                                                |
------------------------------------------------------------------
                                       Copy the code

The results are as follows:

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/hooog.tk/fullchain.pem. Your cert will expire
on 2016-12-03. To obtain a new or tweaked version of this
certificate in the future, simply run letsencrypt-auto again. To
non-interactively renew *all* of your certificates, run
"letsencrypt-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-leCopy the code

Your cert will expire on 2016-12-03

Generate diffie-Hellman Group(Optional)
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048Copy the code

Modify the nginx configuration
server { listen 443 ssl; server_name example.com www.example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; { your config... }}Copy the code

Enable more secure SSL Protocols and Ciphers

Ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_dhparam /etc/ssl/certs/dhparam.pem; ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE -RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA -AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AE S256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA -AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3- SHA:! aNULL:! eNULL:! EXPORT:! DES:! RC4:! MD5:! PSK:! aECDH:! EDH-DSS-DES-CBC3-SHA:! EDH-RSA-DES-CBC3-SHA:! KRB5-DES-CBC3-SHA'; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_stapling on; ssl_stapling_verify on; add_header Strict-Transport-Security max-age=15768000;Copy the code

Redirects non-HTTPS requests

server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}Copy the code

Example Set automatic certificate update
sudo /opt/letsencrypt/letsencrypt-auto renew

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/hooog.tk.conf
-------------------------------------------------------------------------------

The following certs are not due for renewal yet:
/etc/letsencrypt/live/hooog.tk/fullchain.pem (skipped)
No renewals were attempted.Copy the code

Since the certificate is recently updated, the renew command checks only the expiration date

Set up automatic updates once a day and restart Nginx

sudo crontab -e

0 4 * * 1 /opt/letsencrypt/letsencrypt-auto renew >> /var/log/le-renew.log
5 4 * * 1 /etc/init.d/nginx reloadCopy the code