Nginx Install Guide — Ubuntu / CentOS (Specific Versions, Config Structure, Firewall)

1. What is Nginx?

Nginx is a lightweight, high-performance open-source web server and currently the most widely used worldwide. Beyond a simple web server, it plays a key role in solving complex architectural problems as a reverse proxy, load balancer, and mail proxy.

This post covers installation on Ubuntu (Debian family), the most common on cloud servers (AWS EC2, etc.), and CentOS/RedHat (RPM family), preferred in enterprises.

💡 Note — this guide assumes the server is connected to the internet (Public network) so you can use the package manager. On a closed network (Private Subnet), you'd need a manual install via separate binary files.

2. Installing Nginx on Ubuntu (Debian family)

The package manager is apt.

sudo apt update
sudo apt install nginx

In practice you sometimes need a specific version.

apt-cache madison nginx                    # list installable nginx versions in the repo
sudo apt install nginx=1.24.0-2ubuntu7.5   # install a specific version

Service management:

sudo systemctl start nginx
sudo systemctl enable nginx   # auto-start on boot

2.1 Step-by-step detail

Terminal screen of the apt repository update Figure 1. sudo apt update — updating the apt repository

Terminal screen installing nginx with apt Figure 2. sudo apt install nginx — installing nginx

First update the apt repository (recommended, especially to pick up the latest version) and install nginx. Figure 1 is the apt update result, Figure 2 the result of installing nginx from the apt repo. If a (Y/n) prompt appears, enter Y to continue.

Nginx install complete on Ubuntu Figure 3. nginx install complete via apt

Installing nginx via apt auto-registers it as a Linux service, so you can check/start/stop it with systemctl (the manager for Linux services/daemons).

Checking nginx running status with systemctl status Figure 4. systemctl status nginx — checking the running status

Check the status with sudo systemctl status nginx. Installing via apt runs it with a default config.

2.2 Nginx Configuration File Structure and Paths

Path and directory structure of the /etc/nginx config files Figure 5. nginx config path (/etc/nginx/)

When installed via the package manager, all config files live under /etc/nginx/ by default. Nginx config is structured like a "central control room" that loads "detailed instruction sheets."

2.2.1 The central config file: nginx.conf

The top-level config file that determines overall server behavior. Inside, it has statements that include config files from other paths.

include /etc/nginx/modules-enabled/*.conf;   # include module configs
include /etc/nginx/conf.d/*.conf;            # include user-defined configs
include /etc/nginx/sites-enabled/*;          # include individual site configs

The reason to split files is maintainability. Rather than cramming everything into one file, you split it per service and load them with include.

2.2.2 Site config: sites-available vs sites-enabled

The two most important directories in Nginx config.

  • sites-available — the store (originals) of actual per-service config files (ports, routing, etc.).
  • sites-enabled — only configs linked here are actually read and run by Nginx (enabled configs).
  • Usually there's a default file in sites-available containing port (listen), domain (server_name), and routing (location) settings.

2.2.3 Summary: the config flow

  1. nginx.conf — sets the overall frame and orchestrates the detailed configs.
  2. Detailed .conf files — define actual service ports/addresses and run when included into nginx.conf.

3. Installing on CentOS / RedHat (RPM family)

CentOS/RedHat-family (RHEL, Rocky Linux, etc.) use the yum or dnf package manager. The process is very similar to Ubuntu, with one caveat.

3.1 Enable the EPEL repository

CentOS 7+ base repos often don't include Nginx, so you must first install EPEL (Extra Packages for Enterprise Linux), the extra package repo for enterprise Linux.

sudo yum install epel-release -y
sudo yum install nginx -y

Service management is the same as Ubuntu:

sudo systemctl start nginx
sudo systemctl enable nginx

Detailed config and service management after install are the same as the Ubuntu section above, so refer to that.

4. Firewall Setup

If you finished installing Nginx but the browser says "can't connect to this site," it's almost certainly a firewall issue. You must check both the server's own firewall and the AWS security group.

4.1 Linux OS firewall

Depending on the OS, open ports 80 (HTTP) and 443 (HTTPS) with the commands below.

Ubuntu (UFW):

sudo ufw allow 'Nginx Full'

CentOS (firewalld):

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

4.2 AWS security group (if using AWS)

In a cloud (AWS) environment, the Linux-internal settings alone aren't enough. Check the Inbound Rules in the AWS Console instance settings.

  • HTTP (80) — Source 0.0.0.0/0 (allow all)
  • HTTPS (443) — Source 0.0.0.0/0 (allow all)

5. Verifying the Install

Once everything is set, enter the server's public IP in a web browser's address bar.

Welcome to nginx page successfully loaded in a web browser Figure 6. Nginx reached — Welcome to nginx!

If the "Welcome to nginx!" page appears as above, the install and network setup are perfectly complete.


📦 Migrated from my own Korean blog (my own writing). Original: taehyuklee.tistory.com/30

Share𝕏f

Comments