HiBlog

What Is Nginx? How to Install the Nginx Web Server on Ubuntu

  • Ali GhanimatiAuthor
  • Release Date
  • 5 minutesReading time
  • 5Views
  • Ali Ghanimati
  • Published:
  • 5 min read
  • 5 views
What Is Nginx? How to Install the Nginx Web Server on Ubuntu

You’ve got a fresh VPS and want to bring your site or app up on it. The first thing you need is a web server, and the name you hear in almost every tutorial is Nginx: light, fast and versatile. But what exactly is Nginx, and how do you install it properly, without locking yourself out of SSH in the very first step?

In this article we explain what the Nginx web server is and what it can do, then install Nginx on Ubuntu step by step: installing the package, opening the firewall in the right order, checking the service and getting to know its configuration files.

Short answer: Nginx is an open-source, event-driven web server that answers thousands of simultaneous connections with little RAM, and it’s also a reverse proxy, load balancer and cache. On Ubuntu it installs with sudo apt install nginx; just open SSH with sudo ufw allow OpenSSH before you turn on the firewall.

What is Nginx?

Nginx (pronounced “engine-x”) is an open-source web server released in 2004. A web server is software that receives browsers’ requests and delivers pages and files to them; if you’re not familiar with web servers themselves, read What Is a Web Server?

A request going from the browser to the web server and its response

The secret of Nginx’s speed is its architecture: one master process manages several worker processes, and instead of creating a thread for each connection, each worker answers thousands of connections at once in an event-driven way. The result is low RAM and CPU use even under heavy traffic.

What does Nginx do?

  • Web server: it serves static files such as HTML, images, CSS and JavaScript very fast and runs PHP pages through PHP-FPM.
  • Reverse proxy: it sits in front of Node.js, Python or Java apps, handles HTTPS and passes requests to the app; see What Is a Reverse Proxy?
  • Load balancing: it spreads requests across several servers.
  • Caching: it keeps responses so the backend app does less work.

The development server that frameworks like Django or Flask ship with is built for your own computer, not for a public site. On a real server, Nginx sits in front of the app.

Installing Nginx on Ubuntu

We tested these steps on Ubuntu 24.04, and they’re the same on Ubuntu 22.04 and Debian. Connect to the server over SSH; if you don’t know how, see How to Install SSH on Ubuntu.

1. Update the package list

sudo apt update
Updating the package list on Ubuntu

2. Install Nginx

sudo apt install nginx
Installing Nginx with apt on Ubuntu

After installing, check the version. On Ubuntu 24.04, version 1.24 is installed:

nginx -v
Showing the installed Nginx version

3. Open the firewall, in the right order

This is the most important step: if you turn on the UFW firewall before opening SSH, new SSH connections are blocked and you may lose access to the server. So open SSH first, then the web ports, and turn on the firewall last of all:

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable

The Nginx Full profile opens ports 80 and 443; if you only need HTTP or only HTTPS, use Nginx HTTP or Nginx HTTPS. If you moved SSH to another port, open that port instead of OpenSSH, for example sudo ufw allow 2222/tcp. When it turns on, the firewall warns that SSH connections may be disrupted; since you’ve opened SSH, continue with y.

Turning on the UFW firewall and its SSH warning

Check with sudo ufw status that the OpenSSH and Nginx Full rules are in the list.

4. Check the Nginx service

sudo systemctl status nginx
The Nginx service in active (running) state

If Active says active (running), Nginx is up. Now open the server’s IP in a browser; the Welcome to nginx! page means everything works.

Important Nginx files

  • /etc/nginx/nginx.conf: the global settings. In Ubuntu’s version, worker_processes auto creates one worker per CPU core, and worker_connections 768 sets how many connections each worker handles at once.
  • /etc/nginx/sites-available and sites-enabled: each site has a file in sites-available and is enabled with a link in sites-enabled.
  • /var/www/html: the default site’s folder, the welcome page.
  • /var/log/nginx: access.log records every request and error.log the errors.

After any change to the configuration, test it first and then reload Nginx so current connections aren’t dropped:

sudo nginx -t
sudo systemctl reload nginx

FAQ

Can Nginx be installed on Windows too?

There is a Windows version, but the Nginx site itself considers it a beta and says not to expect high performance and scalability from it. For a real server, install Nginx on Linux.

Is Nginx better than Apache?

Nginx answers more traffic with less RAM and is great as a reverse proxy; Apache, with .htaccess files, offers more flexibility for shared sites. We compare the two, plus LiteSpeed, in What Is a Web Server?

HiData Linux VPS

Installing Nginx needs root access, and a HiData VPS comes with Ubuntu, Debian or AlmaLinux and full root access. Want to try this tutorial for free? Get the free 24-hour VPS!

Share Post

hidata.org/en/blog/what-is-nginx-web-server-and-how-to-install-nginx/
In Social Media

Add Comment

Related Articles