Skip to main content

How to install Nginx on Ubuntu VPS

Nginx is a lightweight web server used to host websites, APIs and act as a reverse proxy. See how to install and test Nginx on an Ubuntu VPS.

Requirements

  • Ubuntu VPS;
  • root or sudo access;
  • port 80 available;
  • Public IP of the VPS.
sudo apt update
sudo apt upgrade -y

1. Install Nginx

sudo apt install -y nginx
sudo systemctl enable --now nginx
sudo systemctl status nginx

Press q to exit the status.

2. Release the firewall

sudo ufw app list
sudo ufw allow "Nginx Full"
sudo ufw status

If UFW is not already active, confirm that OpenSSH is enabled before enabling it.

3. Test the server

On VPS:

curl http://localhost

In the browser:

http://IP_DA_VPS

The default page indicates that the installation is complete.

4. Publish a page

The default directory is /var/www/html:

sudo nano /var/www/html/index.html

Add:

<!doctype html>
<html lang="pt-BR">
<head>
<meta charset="utf-8">
<title>Minha VPS com Nginx</title>
</head>
<body>
<h1>Nginx instalado com sucesso!</h1>
</body>
</html>

5. Get to know the files

  • /etc/nginx/nginx.conf: global configuration;
  • /etc/nginx/sites-available/: available sites;
  • /etc/nginx/sites-enabled/: sites enabled;
  • /var/log/nginx/access.log: accesses;
  • /var/log/nginx/error.log: errors;
  • /var/www/html/: default website.

6. Validate before reloading

sudo nginx -t
sudo systemctl reload nginx

Only reload when the test shows no errors.

How to resolve access failure

  1. check systemctl status nginx;
  2. confirm port 80 on the firewall;
  3. check the public IP;
  4. see /var/log/nginx/error.log.

Frequently asked questions

Can Nginx and Apache work together?

Yes, but they cannot listen to the same port and address. It is common to use Nginx as a reverse proxy.

How to host more than one website?

Create blocks in sites-available, activate them in sites-enabled and point the domains to the VPS.

How to set HTTPS?

Point a domain to the VPS and install a TLS certificate. First confirm that the site opens via HTTP.

What is the official reference?

See How to install nginx in the Ubuntu documentation.


If you need help, open a ticket with Nice Hosting support.