> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Install Nginx on Ubuntu, Debian and AlmaLinux

> Install Nginx on Ubuntu 24.04 with sudo apt install nginx, open ports 80 and 443, then check it with nginx -t. Includes Debian 13 and AlmaLinux/Rocky dnf steps.

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.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux / Rocky 9 / 10 | SSH access with sudo |

## Before you start

* Connect to your server with SSH. See [connect with SSH](https://help.freakhosting.com/portals/other/how-to-connect-to-a-linux-server-with-ssh.md).
* 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

> [tab] Ubuntu / Debian
>
> **1. Update the package list**
>
> ```bash theme={null}
> sudo apt update
> ```
>
> **2. Install Nginx**
>
> ```bash theme={null}
> sudo apt install nginx
> ```
>
> Ubuntu and Debian start Nginx and enable it at boot automatically.
>
> **3. Check the service**
>
> ```bash theme={null}
> systemctl status nginx
> ```
>
> Look for `active (running)`. Press `q` to exit.

> [tab] AlmaLinux / Rocky
>
> **1. Install Nginx**
>
> ```bash theme={null}
> sudo dnf install nginx
> ```
>
> **2. Start Nginx and enable it at boot**
>
> ```bash theme={null}
> sudo systemctl enable --now nginx
> ```
>
> On these systems, Nginx does not start by itself after installing.
>
> **3. Check the service**
>
> ```bash theme={null}
> systemctl status nginx
> ```

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

> [!WARNING]
>
> 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](https://help.freakhosting.com/portals/vps-panel/how-to-enable-and-use-vnc-console-access.md).

> [tab] Ubuntu / Debian (ufw)
>
> ```bash theme={null}
> sudo ufw allow 80/tcp
> sudo ufw allow 443/tcp
> sudo ufw status
> ```
>
> On Ubuntu you can also use the profile `sudo ufw allow 'Nginx Full'`, which opens both ports. See [set up ufw](https://help.freakhosting.com/portals/other/how-to-set-up-a-firewall-with-ufw.md).

> [tab] AlmaLinux / Rocky (firewalld)
>
> ```bash theme={null}
> sudo firewall-cmd --permanent --add-service=http --add-service=https
> sudo firewall-cmd --reload
> ```
>
> See [set up firewalld](https://help.freakhosting.com/portals/other/how-to-set-up-a-firewall-with-firewalld.md).

## Where are the Nginx files?

| What | Ubuntu / Debian | AlmaLinux / Rocky |
| - | - | - |
| Main config | `/etc/nginx/nginx.conf` | `/etc/nginx/nginx.conf` |
| Your site configs | `/etc/nginx/sites-available/`, enabled by a link in `/etc/nginx/sites-enabled/` | `/etc/nginx/conf.d/*.conf` |
| Default web root | `/var/www/html` | `/usr/share/nginx/html` |
| Logs | `/var/log/nginx/access.log`, `/var/log/nginx/error.log` | Same |
| Service name | `nginx` | `nginx` |

To host your own domain, create a server block (Nginx's name for a site config). See [set up server blocks](https://help.freakhosting.com/portals/other/how-to-set-up-nginx-server-blocks.md).

## How to check it worked

Test the configuration:

```bash theme={null}
sudo nginx -t
```

Expected output:

```text theme={null}
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
```

Then fetch the page from the server itself:

```bash theme={null}
curl -I http://127.0.0.1
```

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](https://help.freakhosting.com/portals/other/how-to-find-your-server-ip-address.md)) in your browser.

## How to start, stop and reload Nginx

```bash theme={null}
sudo systemctl reload nginx    # apply config changes without dropping connections
sudo systemctl restart nginx   # full restart
sudo systemctl stop nginx
sudo systemctl start 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](https://help.freakhosting.com/portals/other/how-to-fix-website-not-loading-on-your-vps.md).

### 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](https://help.freakhosting.com/portals/other/how-to-install-apache.md).

### How do I add HTTPS?

Point your domain at the server, then run Certbot. See [free SSL with Certbot](https://help.freakhosting.com/portals/other/how-to-get-a-free-ssl-certificate-with-certbot.md).

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every server guide in one place.

> [card] [Nginx server blocks](https://help.freakhosting.com/portals/other/how-to-set-up-nginx-server-blocks.md)
>
> Host one or more domains.

> [card] [Install a LEMP stack](https://help.freakhosting.com/portals/other/how-to-install-a-lemp-stack.md)
>
> Nginx, MariaDB and PHP together.

> [card] [Free SSL with Certbot](https://help.freakhosting.com/portals/other/how-to-get-a-free-ssl-certificate-with-certbot.md)
>
> Add HTTPS to your site.

> [card] [Point a domain to your server](https://help.freakhosting.com/portals/other/how-to-point-a-domain-to-your-server.md)
>
> Set the DNS A record.

> [card] [Nginx reverse proxy](https://help.freakhosting.com/portals/other/how-to-set-up-nginx-as-a-reverse-proxy.md)
>
> Put Nginx in front of an app.

***

> [!NOTE]
>
> **Checked against the official [Ubuntu Server documentation](https://ubuntu.com/server/docs/how-to/web-services/install-nginx/) and [Red Hat Enterprise Linux 9 Nginx guide](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/deploying_web_servers_and_reverse_proxies/setting-up-and-configuring-nginx_deploying-web-servers-and-reverse-proxies)** 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.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.