Website Vidya
DeploymentStep-by-Step Guide

How To Install Nginx on Ubuntu Server: 4 Simple Steps

This guide covers an easy to follow, step-by-step guide on how to install Nginx on Ubuntu Server 18.04 LTE, 16.04, and 14.04. While writing this tutorial I used Ubuntu 18.04 LTE though these resources in the tutorial are useful in installin...

RR
Website Vidya TeamLead Systems Educator
Published:
8 min read
How To Install Nginx on Ubuntu Server: 4 Simple Steps
AI Executive SummaryCORE CIS AI

8 min read

This guide covers an easy to follow, step-by-step guide on how to install Nginx on Ubuntu Server 18.04 LTE, 16.04, and 14.04. While writing this tutorial I used Ubuntu 18.04 LTE though these resources in the tutorial are useful in installin...

Key Highlights
  • Prerequisites
  • How To Install Nginx on Ubuntu Server: Step-by-step
  • Bonus: How to Uninstall Nginx on Ubuntu
Grounded in full engineering runbookCORE CIS Ai Engine

This guide covers an easy to follow, step-by-step guide on how to install Nginx on Ubuntu Server 18.04 LTE, 16.04, and 14.04. While writing this tutorial I used Ubuntu 18.04 LTE though these resources in the tutorial are useful in installing Nginx on Ubuntu 16.04 and 14.04 as well.

Nginx is a high-performance web server and reverse proxy that has become a top choice for developers and system administrators worldwide. Known for its speed, stability, and efficient resource usage, Nginx allows your server to handle thousands of simultaneous connections with minimal overhead. Whether you are hosting a personal website, deploying web applications, or configuring a reverse proxy, learning how to properly install and configure Nginx on Ubuntu is an essential skill.

In this tutorial, we will walk you through the entire Ubuntu Nginx setup, including installing the server, verifying the installation, and performing basic Nginx server configuration to ensure your web environment is secure and ready to serve content.

By following this guide, you will have a fully functional Nginx server on your Ubuntu system, optimized for performance and prepared to handle real-world web traffic efficiently.

If you are looking to install Ubuntu (Linux) with Nginx, MySQL and PHP (LEMP Stack Installation) consider reading:

For Ubuntu Ubuntu (Linux), Apache, MySQL and PHP (LAMP Stack) Installation guide read:

Prerequisites

Before we begin the installation of Nginx on Ubuntu, there are a few requirements to ensure a smooth setup process:

  • Ubuntu Server – You should have a running instance of Ubuntu 18.04 LTE, 16.04, or 14.04. This guide is tested on Ubuntu 18.04 LTE, but the steps apply to the other supported versions as well.
  • Root or Sudo Access – You need to have root privileges or a user account with sudo permissions to install software packages and make system-level changes.
  • Basic Command-Line Knowledge – Familiarity with the Linux terminal will help you execute commands efficiently and troubleshoot minor issues during the installation process.
  • Updated System Packages – It’s recommended to update your system packages to the latest versions before installing Nginx. You can do this using: sudo apt update sudo apt upgrade
  • Firewall Configuration (Optional but Recommended) – If your server has a firewall enabled, you’ll need to allow HTTP (port 80) and HTTPS (port 443) traffic so Nginx can serve web pages.

With these prerequisites in place, you’re ready to start the Ubuntu Nginx setup and get your web server up and running.

How To Install Nginx on Ubuntu Server: Step-by-step

Step 1 - Install Nginx on Ubuntu

Once you are done updating your server, install Nginx on Ubuntu from its default repository using the apt packaging system by running the following command:

sudo apt-get install nginx

Step 2 – Configure the Firewall

Before testing the Nginx installation on Ubuntu, let’s first adjust the firewall to allow access to the service. Nginx by default registers itself as a service with ufw.

You can check the status by running the following command:

Output
Available applications:
  Nginx Full
  Nginx HTTP
  Nginx HTTPS
  OpenSSH

Nginx Full: It means the port 80 is open (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted) are open for http protocol. So that anyone can access the web server by entering the IP address in the web browser.

Nginx HTTP: This only opens port 80 (normal, unencrypted web traffic)

Nginx HTTPS: This opens port 443 (TLS/SSL encrypted)

It is important that we enable all the required profiles for HTTP and HTTPS.

You can see the status by running the following command:

sudo
ufw status

You should see the allowed HTTP and HTTPS traffic. You can see the output below:

Status: active

To                          Action       From
--                          ------       ----
Nginx Full                  ALLOW        Anywhere
Nginx HTTP                  ALLOW        Anywhere
Nginx HTTPS                 ALLOW        Anywhere
Nginx Full (v6)             ALLOW        Anywhere (v6)
Nginx HTTP (v6)             ALLOW        Anywhere (v6)
Nginx HTTPS (v6)            ALLOW        Anywhere (v6)

Step 3 - Checking Your Server

Now you can check the status of your Nginx web server by typing the following command in the terminal:

systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
   Active: active (running) since Thu 2019-01-24 13:12:02 IST; 5 days ago
  Process: 22119 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5
  Process: 22125 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (cod
  Process: 22122 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
 Main PID: 22127 (nginx)
   CGroup: /system.slice/nginx.service
           ├─22127 nginx: master process /usr/sbin/nginx -g daemon on; master_pr
           └─22128 nginx: worker process

Warning: Journal has been rotated since unit was started. Log output is incomple
lines 1-12/12 (END)

We can see that Nginx is started successfully.

So now you need to put the IP address of your server in the web browser to see the Nginx welcome page.

In case you don’t know the IP address of your server, run the following command to display the IP address:

ip addr show
eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Now when you enter the IP address of your server in the browser, you get to see the Welcome page by Nginx.

If you see the above page successfully by running the IP address in the browser, mean that Nginx is configured correctly.

Step 4 – Managing Nginx and its Processes

Below are some of the very useful command that you will need while managing Nginx on your server.

To stop your web server:

sudo
systemctl stop nginx 

or

sudo
service nginx stop

or

sudo
/etc/init.d/nginx stop

To start the web server:

sudo
systemctl start nginx 

or

sudo
service nginx start

or

sudo
/etc/init.d/nginx start

To restart the web server:

sudo
systemctl restart nginx

or

sudo
service nginx restart

or

sudo
/etc/init.d/nginx restart

To reload the Nginx without dropping the connection you can run the reload command:

sudo
systemctl reload nginx

or

sudo
service nginx reload

or

sudo
/etc/init.d/nginx reload

In any case, if you need to disable your web server, you might want to run the disable command:

sudo
systemctl disable nginx

To enable web server:

sudo
systemctl enable nginx

That’s it!

You are done installing and configuring Nginx web server. For more information regarding Nginx documentation, check official documentation by Nginx.

If you need to install a WordPress installation using Ubuntu, Nginx and MySQL read WordPress Installation guide on LEMP with Ubuntu.

Bonus: How to Uninstall Nginx on Ubuntu

While Nginx is a reliable and lightweight web server, there may be situations where you need to remove it from your Ubuntu system—whether to troubleshoot issues, switch to a different web server, or start fresh. Here’s a simple guide to uninstall Nginx safely.

Step 1: Stop the Nginx Service

Before uninstalling, stop Nginx to ensure no processes are running:

sudo systemctl stop nginx

Step 2: Remove Nginx Packages

To remove Nginx without deleting configuration files, use:

sudo apt remove nginx

If you want to remove Nginx along with its configuration files, use the purge command:

sudo apt purge nginx

Step 3: Remove Unused Dependencies

After removal, you can clean up any unused packages and dependencies:

sudo apt autoremove

Step 4: Verify Removal

Check if Nginx has been completely removed:

nginx -v

If Nginx is uninstalled, you will see a command not found error.

Optional: Remove Nginx Directories

If you want to completely clean up your server, you can delete remaining Nginx directories:

sudo rm -rf /etc/nginx
sudo rm -rf /var/www/html

By following these steps, you can safely uninstall Nginx from your Ubuntu system and prepare it for a fresh installation or alternative web server setup.

Conclusion

In this guide, we covered how to install Nginx on Ubuntu 18.04 LTE, 16.04, and 14.04, along with the essential steps for verifying the installation and performing basic Nginx server configuration. Nginx is a powerful, high-performance web server that is widely used for hosting websites, web applications, and acting as a reverse proxy, making it an essential tool for developers and system administrators.

By following this Ubuntu Nginx setup tutorial, you now have a fully functional web server ready to handle web traffic efficiently and securely. From here, you can explore advanced configurations such as enabling SSL, setting up virtual hosts, optimizing performance, and integrating Nginx with application servers like PHP-FPM or Node.js.

Whether you are deploying your first website or managing multiple web applications, mastering Nginx on Ubuntu provides a stable and scalable foundation for all your web hosting needs.

I hope you will find this guide on how to install Nginx on Ubuntu Server 18.04, 16.04 and 16.04 useful.

If you have any other web application to install, you can put it in the comment section or mail me on my email address. I will personally get in touch with you to help you setup your application.

If you found this guide useful, don’t forget to bookmark it for future reference and share it with others looking to set up their own Nginx server on Ubuntu.

If you need to install a WordPress installation using Ubuntu, Nginx and MySQL read WordPress Installation guide on LEMP with Ubuntu.


FAQs: How To Install Nginx on Ubuntu Server

Nginx is a high-performance web server, reverse proxy, and load balancer known for its speed, stability, and low resource usage. Using Nginx on Ubuntu ensures a reliable environment to host websites, web applications, or APIs efficiently.

You can install Nginx on Ubuntu 18.04 LTE, 16.04, and 14.04. While this guide uses Ubuntu 18.04 LTE, the commands and configuration steps are compatible with the other supported versions.

After installation, you can check the status of Nginx with:

sudo systemctl status nginx

If Nginx is running, you will see an active status. You can also open your server’s IP address in a web browser; the default Nginx welcome page confirms the installation.

If your server has UFW (Uncomplicated Firewall) enabled, run the following commands to allow HTTP and HTTPS traffic:

sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status

Yes, this tutorial sets up the base Nginx server configuration. You can later configure Nginx as a reverse proxy for applications like Node.js, Python, or PHP by editing server blocks and proxy settings.

To remove Nginx, you can run:

sudo apt remove nginx
sudo apt purge nginx
sudo apt autoremove

This removes Nginx and associated configuration files from your server.

Absolutely. Once Nginx is installed, you can enable SSL using free certificates from Let’s Encrypt and configure HTTPS for secure web traffic.

Written by

Website Vidya Team

Technology educator and researcher at Website Vidya.

Discussion

0
Share your thoughts, ask a question, or suggest a tip...
Write →

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Deployment•

How to Install PDO Extension in PHP

PHP Data Objects (PDO) is one of the most important extensions in PHP for working with databases in a secure, consistent, and modern way. If you are building dynamic websites, APIs, CMS platforms, or enterprise applications, PDO is not opti...

RR
Rajesh Rai
Read More
Deployment•

How to Install PHPMyAdmin on Ubuntu: 4 Simple Steps

If you’re working with MySQL or MariaDB on Ubuntu, managing databases purely from the command line can quickly feel overwhelming. That’s where phpMyAdmin comes in. PHPMyAdmin is a web-based application that provides a Graphical User Interfa...

RR
Rajesh Rai
Read More
Deployment•

25 Best Linux Commands Every Sysadmin Should Know

If you’ve spent any time managing Linux servers, you already know this truth: the command line is not optional. It’s where real troubleshooting happens, where performance issues are understood, and where outages are prevented before users e...

RR
Rajesh Rai
Read More
Deployment•

How to Fix Snapd Consuming High CPU / RAM on Linux

If you’ve ever opened your system monitor and noticed snapd quietly eating up your CPU or RAM, you’re not alone. Many Linux users—especially on Ubuntu and Ubuntu-based distributions—eventually run into this issue and wonder what’s going on ...

RR
Rajesh Rai
Read More
Deployment•

How to Fix Broken Packages in Ubuntu: 7 Simple Ways

If you’ve been using Ubuntu for a while, chances are you’ve run into package-related issues at least once. A failed update, an interrupted installation, or conflicting dependencies can easily leave your system in a messy state. When that ha...

RR
Rajesh Rai
Read More