{"id":365,"date":"2019-05-15T14:06:29","date_gmt":"2019-05-15T14:06:29","guid":{"rendered":"https:\/\/blog.iabsolute.com\/?p=365"},"modified":"2019-05-15T14:06:29","modified_gmt":"2019-05-15T21:06:29","slug":"free-https-encryption-for-your-site-using-lets-encrypt-and-nginx","status":"publish","type":"post","link":"https:\/\/blog.iabsolute.com\/?p=365","title":{"rendered":"free HTTPS encryption for your site using Let&#8217;s Encrypt and nginx"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Step 1, get the certbot-auto certificates manager:<\/h2>\n\n\n\n<p>\nOpen your server console and download the certificate manager app from&nbsp;<a href=\"https:\/\/certbot.eff.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/certbot.eff.org\/<\/a>.<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/usr\/local\/bin\/ &amp;&amp; sudo wget https:\/\/dl.eff.org\/certbot-auto &amp;&amp; sudo chmod a+x certbot-auto\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\nStep 2, run certbot-auto certificates manager:<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo certbot-auto certonly -a webroot --webroot-path=\/var\/www\/example.com\/public_html -d example.com -d www.example.com\n<\/pre>\n\n\n\n<p>\nDepending on if this is your first time attempt to get free Let&#8217;s Encrypt certificates, the procedure above may ask you some questions, like an email address used for communications, if you agree that your ip to be logged for this request (you must agree), terms and conditions (you also must agree) and even newsletter (you choose).<br>\nNext, the certbot-auto will install\/update some dependencies and then creates an temporary (used for domain validation) .well-known\/acme-challenge file at the root of the example.com<sup>*)<\/sup> declared host.<br><sup>*)<\/sup><em>example.com must already have a DNS entry pointing to your server IP<\/em><br><br>\nIf all goes well, you should see a congratulation message and other important infos.<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Congratulations! Your certificate and chain have been saved at\n   \/etc\/letsencrypt\/live\/example.com\/fullchain.pem. Your cert will\n   expire on 2017-06-16. To obtain a new or tweaked version of this\n   certificate in the future, simply run certbot-auto again.\n<\/pre>\n\n\n\n<p>\nCheck that all the certificates are in place<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo ls \/etc\/letsencrypt\/live\/example.com\ncert.pem  chain.pem  fullchain.pem  privkey.pem  README\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\nStep 3, Diffie-Hellman Group:<\/h2>\n\n\n\n<p>\n\nGenerate a <a href=\"http:\/\/www.watchguard.com\/help\/docs\/wsm\/xtm_11\/en-us\/content\/en-us\/bovpn\/manual\/diffie_hellman_c.html\" target=\"_blank\" rel=\"noreferrer noopener\">medium strong<\/a><a href=\"https:\/\/en.wikipedia.org\/wiki\/Diffie%E2%80%93Hellman_key_exchange\" target=\"_blank\" rel=\"noreferrer noopener\">Diffie-Hellman<\/a> key exchange. This will take some time, depending on your server processing power, so issue the below command then go and grab a coffee. If you run this on a under-powered VPS (1vCPU), I will recommend you to run the command on another machine with more horse power and then just copy the resulted file to your server.\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo openssl dhparam -out \/etc\/letsencrypt\/dhparam.pem 2048\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\nStep 4, NGINX server block:<\/h2>\n\n\n\n<p>\n\nNow that we have all the files in place, just add these lines to the NGINX example.com server block, save the file and reload\/restart NGINX.\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">server {\n  listen 80;\n  listen 443 ssl http2;\n  server_name example.com www.example.com;\n  if ($host = \"example.com\") {\n       return 301 https:\/\/www.example.com$request_uri;\n      }\n  if ($scheme = http) {\n   return 301 https:\/\/www.example.com$request_uri;\n  }\n  \n  \n  ssl_certificate \/etc\/letsencrypt\/live\/example.com\/fullchain.pem;\n  ssl_certificate_key \/etc\/letsencrypt\/live\/example.com\/privkey.pem;\n  \n  ssl_session_cache shared:SSL:20m;\n  ssl_session_timeout 180m;\n  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;\n  ssl_prefer_server_ciphers on;\n  ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;\n  \n  ssl_dhparam \/etc\/letsencrypt\/dhparam.pem;\n  \n  ssl_stapling on;\n  ssl_stapling_verify on;\n  \n  ssl_trusted_certificate \/etc\/letsencrypt\/live\/example.com\/chain.pem;\n  \n  ....\n}\n<\/pre>\n\n\n\n<p><em>a comprehensive NGINX server block example:<br>https:\/\/github.com\/b247\/WebH-NL\/blob\/master\/files\/vhosts\/fqdn-nginx-ssl.conf<\/em><br>\nCheck that your site works as expected and then make a SSL test here:&nbsp;<a href=\"https:\/\/www.ssllabs.com\/ssltest\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.ssllabs.com\/ssltest\/<\/a><br><br>\nAssuming that you&#8217;ve also got a nice A+ free SSL protected site badge, then we&#8217;re almost done, one last step to take:<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\nStep 5, automatic certificate renewal:<\/h2>\n\n\n\n<p>\n\nAs Let&#8217;s Encrypt certificates have a short renewal period (3 months), it&#8217;s hard to manually monitor and update those certificates. Here comes in handy the renew switch of the certbot-auto and the crontab.\n\nLaunch the crontab editor (sudo crontab -e), add following lines, save it and you are done. (afraid of crontab rules?, just visit <a href=\"https:\/\/crontab.guru\/\" target=\"_blank\" rel=\"noreferrer noopener\">crontab.guru<\/a> and and you will be enlightened)\n\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Let's Encrypt automatic certificates renewal\n59 23 * * 0          \/usr\/local\/bin\/certbot-auto renew --renew-hook \"systemctl reload nginx\"\n<\/pre>\n\n\n\n<p>\n\nThat&#8217;s all folks!\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step 1, get the certbot-auto certificates manager: Open your server console and download the certificate manager app from&nbsp;https:\/\/certbot.eff.org\/. cd \/usr\/local\/bin\/ &amp;&amp; sudo wget https:\/\/dl.eff.org\/certbot-auto &amp;&amp; sudo chmod a+x certbot-auto Step 2, run certbot-auto certificates manager: sudo certbot-auto certonly -a webroot &hellip; <a href=\"https:\/\/blog.iabsolute.com\/?p=365\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-365","post","type-post","status-publish","format-standard","hentry","category-ssl"],"_links":{"self":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=365"}],"version-history":[{"count":1,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/365\/revisions"}],"predecessor-version":[{"id":366,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/365\/revisions\/366"}],"wp:attachment":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}