{"id":233,"date":"2020-09-30T01:37:21","date_gmt":"2020-09-30T01:37:21","guid":{"rendered":"https:\/\/dft.wiki\/?p=233"},"modified":"2026-06-09T14:40:14","modified_gmt":"2026-06-09T18:40:14","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 blog to make a post, you are typing your password, and this password is traveling over the internet as plain text, unencrypted.<\/p>\n<p>More often than you might think, someone connected to your network (especially on public Wi-Fi) can intercept and read your credentials. Since many people reuse passwords, an attacker could gain access to your blog, social media accounts, or 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 its content:<\/p>\n<pre>&lt;VirtualHost *:80&gt;\r\n...\r\n&lt;\/VirtualHost&gt;<\/pre>\n<p>At the end of the first block, add the following lines if you want the web server to always redirect 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 alternatives in this post [<a href=\"https:\/\/dft.wiki\/?p=1364\">Link<\/a>].<\/p>\n<p>You need to open the port in the firewall and enable the required 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 web server:<\/p>\n<pre>sudo apache2ctl configtest\r\nsudo systemctl restart apache2<\/pre>\n<p>Apache2 will request a certificate from Let&#8217;s Encrypt for your domain (this may take about 1 minute). You can monitor the process with:<\/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 example.com has been set up and changes will be activated on the next (graceful) server restart.<\/p>\n<p>This means the server needs to be restarted one more time for the changes to take effect.<\/p>\n<p>From a Linux client you can check the connection status with and without encryption:<\/p>\n<pre>curl -I http:\/\/example.com\r\ncurl -I https:\/\/example.com<\/pre>\n<p>The certificate for your domain expires in 90 days. To ensure it renews automatically without interruptions, make sure the mod_watchdog module is installed:<\/p>\n<pre>sudo apache2ctl -M | grep mod_watchdog<\/pre>\n<p>Expected output: <strong>watchdog_module (static)<\/strong><\/p>\n<p>You can also monitor the status of your certificate by visiting: <strong>https:\/\/example.com\/server-status<\/strong><\/p>\n<p>To enable this, go back into the configuration file and add the following at the end (remember to restart Apache):<\/p>\n<pre>&lt;Location \"\/md-status\"&gt;\r\nSetHandler md-status\r\n&lt;\/Location&gt;<\/pre>\n<p>You can also look up your domain on Certificate Search [<a href=\"https:\/\/crt.sh\/\">Here<\/a>] for more details 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":16,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/233\/revisions"}],"predecessor-version":[{"id":5832,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/233\/revisions\/5832"}],"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}]}}