{"id":233,"date":"2020-09-30T01:37:21","date_gmt":"2020-09-30T01:37:21","guid":{"rendered":"https:\/\/dft.wiki\/?p=233"},"modified":"2026-04-21T13:36:06","modified_gmt":"2026-04-21T17:36:06","slug":"ssl-tls-on-ubuntu-20-04-and-apache","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=233","title":{"rendered":"SSL\/TLS on Ubuntu and Apache"},"content":{"rendered":"<p>Why do I need SSL\/TLS?<\/p>\n<p>Maybe your website does not require any sensitive personal information such as a credit card or SIN, but if you simply log in to your block to make a post you are typing your password, and this password is traveling on the internet as a plain text, unencrypted.<\/p>\n<p>Easily (and more often than you think) someone connected to your network or if you are in public wifi (this is the worse scenario) can read and get your credentials. Often we share passwords to make it easier to remember, and then someone can possibly still your blog, your social network account, or your email. So, you need SSL\/TLS!<\/p>\n<pre>sudo apt update\r\nsudo apt upgrade\r\nsudo apt install libapache2-mod-md\r\nsudo a2enmod md\r\nsudo systemctl restart apache2\r\nsudo a2enmod ssl\r\nsudo systemctl reload apache2<\/pre>\n<p>Edit the configuration file of the site you want to protect:<\/p>\n<pre>sudo nano \/etc\/apache2\/sites-available\/example.com.conf<\/pre>\n<p>Add at the top of the file:<\/p>\n<pre>ServerAdmin webmaster@example.com\r\nMDCertificateAgreement accepted\r\nMDomain example.com\r\nMDPrivateKeys RSA 4096<\/pre>\n<p>Duplicate the configuration block below with all the content in it:<\/p>\n<pre>&lt;VirtualHost *:80&gt;\r\n...\r\n&lt;\/VirtualHost&gt;<\/pre>\n<p>At the end of the first block you can add the following lines if you want the webserver to always change from plain text to encrypted:<\/p>\n<pre>&lt;VirtualHost *:80&gt;\r\n...\r\nRewriteEngine On\r\nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}$1 [R=301,L]\r\n&lt;\/VirtualHost&gt;<\/pre>\n<p>The second block will look like this:<\/p>\n<pre>&lt;VirtualHost *:443&gt;\r\nSSLEngine on\r\nSSLProtocol all -SSLv2 -SSLv3\r\nSSLHonorCipherOrder on\r\n<strong>SSLCipherSuite<\/strong> \"EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS +RC4 RC4\"\r\n...\r\nProtocols h2 http\/1.1\r\nHeader always set Strict-Transport-Security \"max-age=63072000\"\r\n&lt;\/VirtualHost&gt;<\/pre>\n<p>Note: use the recommended <strong>SSLCipherSuite<\/strong> above or read more about it in this post [<a href=\"https:\/\/dft.wiki\/?p=1364\">Link<\/a>] to get alternatives.<\/p>\n<p>You need to add this permission in the firewall and enable the modules:<\/p>\n<pre>sudo ufw allow 443\/tcp\r\nsudo a2enmod rewrite\r\nsudo a2enmod headers<\/pre>\n<p>You can always check your configuration before reloading the webserver:<\/p>\n<pre>sudo apache2ctl configtest\r\nsudo systemctl restart apache2<\/pre>\n<p>The Apache2 will request from Let\u2019s Encrypt to get the certification for your domain (may take 1 minute). You can monitor the process by issuing the commands:<\/p>\n<pre>sudo tail -f \/var\/log\/apache2\/error.log<\/pre>\n<p>OR<\/p>\n<pre>sudo grep 'The Managed Domain' \/var\/log\/apache2\/error.log<\/pre>\n<p>The expected response in the log file looks like this:<\/p>\n<p>The Managed Domain exemple.com has been set up and changes will be activated on the next (graceful) server restart.<\/p>\n<p>Indicating that the server needs to be restarted once more to take effect.<\/p>\n<p>From a Linux client computer you can check the status of the connection with and without encryption:<\/p>\n<pre>curl -I http:\/\/example.com\r\ncurl -I https:\/\/example.com<\/pre>\n<p>The new certificate for your domain will expire in 90 days. Keep on top of it to make sure it will be renewed without interruptions with the module mod_watchdog. First check if it is installed:<\/p>\n<pre>sudo apache2ctl -M | grep mod_watchdog<\/pre>\n<p>The expected output: <strong>watchdog_module (static)<\/strong><\/p>\n<p>And you can always monitor the status of your certificate by visiting the address: <strong>https:\/\/example.com\/server-status<\/strong><\/p>\n<p>For it, go back into the configuration file and add this code at the end (remember to restart the Apache):<\/p>\n<pre>&lt;Location \"\/md-status\"&gt;\r\nSetHandler md-status\r\n&lt;\/Location&gt;<\/pre>\n<p>You can also search for your domain on Certificate Search [<a href=\"https:\/\/crt.sh\/\">Here<\/a>] to see more information about this and other certificates.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why do I need SSL\/TLS? Maybe your website does not require any sensitive personal information [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-233","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=233"}],"version-history":[{"count":15,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/233\/revisions"}],"predecessor-version":[{"id":5500,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/233\/revisions\/5500"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}