Skip to main content
To install Nginx on Ubuntu 24.04 or Debian 13, run sudo apt update && sudo apt install nginx. On AlmaLinux or Rocky Linux, run sudo dnf install nginx and then sudo systemctl enable --now nginx. Allow ports 80 and 443 in your firewall, then open http://203.0.113.10 (your server’s IP) in a browser. You see the Nginx welcome page when it works.

Before you start

  • Connect to your server with SSH. See connect with SSH.
  • Use a user with sudo rights. If you are logged in as root, leave out sudo.
  • Only one program can listen on port 80. If Apache is already installed, stop it first or use a different port.
Nginx (pronounced “engine-x”) is a web server: it answers browser requests on ports 80 (HTTP) and 443 (HTTPS) and sends back your website, or passes the request on to an app.

How to install Nginx

1

Update the package list

2

Install Nginx

Ubuntu and Debian start Nginx and enable it at boot automatically.
3

Check the service

Look for active (running). Press q to exit.
Package versions differ by release: Ubuntu 24.04 ships Nginx 1.24, Debian 13 and AlmaLinux 10 ship Nginx 1.26.

How to open ports 80 and 443 in the firewall

Only add rules here. Do not enable a firewall for the first time without allowing SSH, or you lock yourself out. If that happens, use the VNC console.
On Ubuntu you can also use the profile sudo ufw allow 'Nginx Full', which opens both ports. See set up ufw.

Where are the Nginx files?

To host your own domain, create a server block (Nginx’s name for a site config). See set up server blocks.

How to check it worked

Test the configuration:
Expected output:
Then fetch the page from the server itself:
You should see HTTP/1.1 200 OK and a Server: nginx header. Finally, open http://203.0.113.10 (replace with your server IP) in your browser.

How to start, stop and reload Nginx

Always run sudo nginx -t before a reload. If the test fails, Nginx keeps running with the old config, and the error message names the file and line to fix.

Frequently asked questions

Why can’t I see the Nginx page from my browser?

Check three things: the service is active (running), your firewall allows port 80, and you used the right IP. curl -I http://127.0.0.1 on the server tells you whether Nginx itself works. See website not loading.

Nginx fails to start with “Address already in use”. What now?

Another program, usually Apache, already uses port 80. Find it with sudo ss -tlnp | grep ':80', then stop it (sudo systemctl stop apache2 or httpd) or change one of them to a different port.

Should I use Nginx or Apache?

Both are fine for most sites. Nginx is a common choice as a reverse proxy in front of Node.js or Python apps. Apache supports .htaccess files, which some PHP apps expect. See install Apache.

How do I add HTTPS?

Point your domain at the server, then run Certbot. See free SSL with Certbot.

VPS and dedicated server guides

Every server guide in one place.

Nginx server blocks

Host one or more domains.

Install a LEMP stack

Nginx, MariaDB and PHP together.

Free SSL with Certbot

Add HTTPS to your site.

Point a domain to your server

Set the DNS A record.

Nginx reverse proxy

Put Nginx in front of an app.

Checked against the official Ubuntu Server documentation and Red Hat Enterprise Linux 9 Nginx guide on 4 November 2026; install and configuration test commands tested on Ubuntu 24.04 LTS (Nginx 1.24.0). Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026