1.   Overview

SSL/TLS enryption of your website leads to higher search rankings and better security for your users. With Let’s Encrypt, they are no longer a concern. Let’s Encrypt makes SSL/TLS encryption freely available to everyone.

Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It is a lightweight choice that can be used as either a web server or reverse proxy.

In this guide, we’ll discuss how to install Nginx on your Ubuntu 20.04 server, adjust the firewall, manage the Nginx process, and set up server blocks for hosting more than one domain from a single server.

2.   Prerequisites

Domain: www.example.com
Internet to get package: nginx; certbot

3.   Setup

  • Install nginx
$ apt-get update
$ sudo apt-get install certbot
$ apt-get install python-certbot-nginx

Note: Sometimes I will be get errors after start nginx:”nginx.service:Failed to read PID from file /run/nginx.pid: Invalid argument ubuntu 16.04 xenial”

$ printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
$ systemctl daemon-reload
$ systemctl start nginx
  • Disable the default virtual host which is pre-configured when Nginx is installed via Ubuntu’s packet manager apt:
$ unlink /etc/nginx/sites-enabled/default
  • Enter the directory /etc/nginx/sites-available and create a reverse proxy configuration file.
$ cd /etc/nginx/sites-available
$ nano reverse-proxy.conf
  • Paste the following Nginx configuration in the text editor.
    The proxy server redirects all incomming connections on port 80 to the Webfsd server, listening on port 8080.
server {
        listen 80;
        listen [::]:80;
        access_log /var/log/nginx/reverse-access.log;
        error_log /var/log/nginx/reverse-error.log;
        location / {
                    proxy_pass http://localhost:8080;

Note: Contains a server_name directive with the domain name you’re requesting a certificate for. In our example, the domain is www.example.com.

server {
        listen 80;
        listen [::]:80;
server_name example.com www.example.com;
access_log /var/log/nginx/reverse-access.log;
        error_log /var/log/nginx/reverse-error.log;
        location / {
  • Copy the configuration from /etc/nginx/sites-available to /etc/nginx/sites-enabled. It is recommended to use a symbolic link.
$ ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
  • Test the Nginx configuration file
nginx -t
  • Done
Part 1: How to install NGINX in Ubuntu
Tagged on:         

One thought on “Part 1: How to install NGINX in Ubuntu

Leave a Reply

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