CrownCloud Wiki

CrownCloud - Internet Services

User Tools

Site Tools


To setup letsencrypt with Nginx, first you will need to install prerequisites

apt-get install sudo
apt-get install nano

Get the letsencrypt certificate file, and run it

cd /usr/local/sbin

If you haven't already, install Nginx

sudo apt-get update
sudo apt-get install nginx

Make the letsencrypt client file executable

sudo chmod a+x /usr/local/sbin/certbot-auto

Add the .well-known directory to your nginx configuration to make sure it will be accessible to the letsencrypt client

sudo nano /etc/nginx/sites-available/default

Adding the following location line to the server block in your Nginx configuration

location ~ /.well-known {
                allow all;

Check the Nginx configuration, for any errors that could have occured.

sudo nginx -t

Restart Nginx

sudo service nginx restart

Generate the SSL certificate using the letsencrypt client (Note: Change the webroot directory if necessary, and change and to the domain you would like to have SSL enabled on.

certbot-auto certonly -a webroot --webroot-path=/usr/share/nginx/html -d -d

If everything was successful, you should end up seeing something like this

 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/ Your
   cert will expire on 2017-01-03. To obtain a new or tweaked version
   of this certificate in the future, simply run certbot-auto again.
   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:
   Donating to EFF:          

To further increase the security of your website, you should also generate a strong Diffie-Hellman group

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

To add the SSL certificate to your website, you will again need to edit the configuration file

sudo nano /etc/nginx/sites-available/default

Find the server block, and comment out the lines that configure the server to listen on port 80.

Next, you will need to configure your server to listen on port 443. (Note: Edit all instances of to your own domain)

        listen 443 ssl;


        ssl_certificate /etc/letsencrypt/live/;
        ssl_certificate_key /etc/letsencrypt/live/;

To allow the strongest SSL cipers and protocols, also add this to your configuration file under what we just added.

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_dhparam /etc/ssl/certs/dhparam.pem;
        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;

(Optional) To redirect all traffic to SSL, you will need to add this into your server block under server_name

return 301 https://$host$request_uri;

Test your Nginx configuration file, and restart nginx

sudo nginx -t
sudo service nginx restart

To renew all of your certificates at once when they expire, you can run

certbot-auto renew

And finally, you will have SSL on your website for free.

letsencrypt_with_nginx.txt · Last modified: 2016/10/05 06:21 by jordan