Install Let’s Encrypt for Nginx on Ubuntu 18

This is just a quick note to Install Let’s Encrypt for Nginx on Ubuntu 18. Since there is a new way to automatically renew LE certs on Ubuntu 18, I quick document steps for the reference purpose.

  1. Install Let’s encrypt for Nginx: apt install -y python-certbot-nginx
  2. Issue necessary certs for your domain with LE (remember that you need to have Nginx server blocks for these domains first) : certbot --nginx -d YOUR_DOMAIN1.COM -d YOUR_DOMAIN2.COM
  3. We can check if we currently have certbot in the system timers for automatically renewal: systemctl list-timers
  4. In order to restart nginx when certs are renewed, we can simply add renewal-hook to the /etc/letsencrypt/cli.ini file as follows: renew-hook = systemctl reload nginx
    • Note 1: you can of course use certbot renew --pre-hook "service nginx stop" --post-hook "service nginx start" for your scheduled tasks / cronjobs.
    • Note 2: you can also create a bash file at /etc/letsencrypt/renewal-hooks/deploy/ to implement renewal hooks, just remember to allow it to be executable.
  5. Done 🙂

Bonus: Password protected folder

  • Install apache2-utils so that we can use the htpasswd command: apt install apache2-utils
  • Create password with htpasswd: htpasswd -c /home/MYDOMAIN/.htpasswd USERNAME
  • Add a new block to nginx configuration to protect your private folder:
    location /YOUR_FOLDER {
            autoindex on;
            auth_basic "Restricted";
            auth_basic_user_file /home/MYDOMAIN/.htpasswd;
    }
  • Restart nginx: systemctl restart nginx

Bonus: Install Fail2Ban and use w/ SSH

  • Install it: apt-get install -y fail2ban
  • Configure a new jail at /etc/fail2ban/jail.local:
[sshd]
enabled = true
port = 899
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
  • Restart it: systemctl restart fail2ban
  • Similar Posts

    • Install Chef server Lets Encrypt

      Do not want to mention what Chef is, or what Let’s Encrypt is. This is just a short step-by-step tutorial to guide you how to install Chef server Lets Encrypt for the server SSL. Setup Let’s Encrypt First, install let’s encrypt to generate a standalone certificate before installing chef server: [bash]git clone https://github.com/letsencrypt/letsencrypt cd letsencrypt…

    • Install PHP 5.5 with OpCache and Google PageSpeed

      This tutorial guides step-by-step on how to install most recent/most updated versions of a regular PHP stack. This comprises PHP 5.5 with OpCache, Percona 5.6 server and Google PageSpeed for Apache HTTPD Import needed repo for PHP 5.5:[bash]rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm [/bash] Install PHP 5.5 and related softwares:[bash]yum –enablerepo=remi,remi-php55 install httpd php php-common…

    • Beanstalk Messaging Queue

      When researching about Messaging Queue softwares, I found a very useful blog at http://nubyonrails.com/articles/about-this-blog-beanstalk-messaging-queue, so I decide to re-post here for future reference as well as for anyone who is interested in. FIGURE A Messaging queues are a tool for executing code without taxing your web application processes. Web developers often get into the rut of thinking…

    • Docker – Beginner’s Notes

      Well, after a year returning to Docker, I can still be considered as a beginner since I forgot almost things that I did before :shame: So this entry, Docker – Beginner’s Notes, is just a way that helps me in the future (hopefully). Useful commands to remember: docker images, docker ps -a, docker rm <container_name>, docker…

    Leave a Reply

    Your email address will not be published. Required fields are marked *