How to Install and Configure Nginx on Ubuntu 20.04

Nginx (pronounced as “Engine-X”) is an open source and lightweight web server that is often used as reverse proxy or HTTP cache. In this post i will share how we can install and do basic configuration of Nginx on Ubuntu 20.04.

1) Install nginx :

$ sudo apt -y install nginx

2) Basic Nginx configuration :

linodelinux@ubuntu20:~$ sudo vi /etc/nginx/sites-available/default

Add the following under “server_name” :

How to Install and Configure Nginx on Ubuntu 20.04

3) Check syntax :

linodelinux@ubuntu20:~$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

4) Restart nginx service :

linodelinux@ubuntu20:~$ sudo systemctl restart nginx

5) Make nginx auto start at boot :

linodelinux@ubuntu20:~$ sudo systemctl enable nginx
Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable nginx

6) Test if nginx can be access at url http://test2.local
How to Install and Configure Nginx on Ubuntu 20.04

Leave a Comment