Deployment Plan Table

Operating System IP NGINX Version
Rocky9.5(x86_64) 192.168.225.32 1.26.3

Here, I’ll only introduce how to install nginx by the rpm repository. As to the build-install method, I’ll introduce in the later chapter.

Prerequisites

Preparing the software repository

I would like to add a new repository in the path /etc/yum.repos.d/nginx.repo.

1
2
3
4
5
6
7
cat > /etc/yum.repos.d/nginx.repo <<EOF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/9/x86_64/
gpgcheck=0
enabled=1
EOF

Generating the index of repository

1
2
3
4
5
6
7
8
9
[root@localhost ~]# dnf makecache
nginx repo 8.7 kB/s | 2.9 kB 00:00
Rocky Linux 9 - BaseOS 4.8 kB/s | 4.1 kB 00:00
Rocky Linux 9 - BaseOS 1.0 MB/s | 2.3 MB 00:02
Rocky Linux 9 - AppStream 1.8 kB/s | 4.5 kB 00:02
Rocky Linux 9 - AppStream 8.4 MB/s | 8.5 MB 00:01
Rocky Linux 9 - Extras 3.7 kB/s | 2.9 kB 00:00
Rocky Linux 9 - Extras 15 kB/s | 16 kB 00:01
Metadata cache created.

`` Installing NGINX

Similarly, you can install nginx using the following command in RockyLinux terminal : sudo yum -y install nginx . After installation is complete it will be available for use via http.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@localhost ~]# dnf install nginx -y
...
==============================================================================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================================================================
Installing:
nginx x86_64 2:1.26.2-2.el9.ngx nginx 996 k

Transaction Summary
==============================================================================================================================================================================================================
Install 1 Package

Total download size: 996 k
Installed size: 3.3 M
Downloading Packages:
nginx-1.26.3-2.el9.ngx.x86_64.rpm 428 kB/s | 996 kB 00:02
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Installed:
nginx-2:1.26.3-2.el9.ngx.x86_64
...
Complete!
[root@localhost ~]#

Preparing the test webpage

NGINX has been installed, so let’s test whether it can serve a webpage. By default, NGINX requires us to place web pages in the /usr/share/nginx/html directory, with the homepage named either index.html or index.htm.

I have prepared a homepage with the content: “Hello nginx, I’m Haoyang Sun!”.

1
2
3
[root@localhost ~]# echo "Hello nginx, I'm Haoyang Sun!" > /usr/share/nginx/html/index.html
[root@localhost ~]# cat /usr/share/nginx/html/index.html
Hello nginx, I'm Haoyang Sun!

Enabling and starting the service

Here, we use the enable --now syntax to perform both the enable and start operations on the NGINX service.

This ensures that the NGINX service starts immediately and is configured to launch automatically on boot.

1
2
[root@localhost ~]# systemctl enable nginx --now
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

Check the status of nginx service.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: disabled)
Active: active (running) since Sun 2025-03-09 23:47:45 EDT; 3h 2min ago
Docs: http://nginx.org/en/docs/
Process: 21534 ExecStart=/usr/sbin/nginx -c ${conffile} (code=exited, status=0/SUCCESS)
Main PID: 21535 (nginx)
Tasks: 5 (limit: 47268)
Memory: 5.1M
CPU: 16ms
CGroup: /system.slice/nginx.service
├─21535 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
├─21536 "nginx: worker process"
├─21537 "nginx: worker process"
├─21538 "nginx: worker process"
└─21539 "nginx: worker process"

Mar 09 23:47:45 localhost.localdomain systemd[1]: Starting nginx - high performance web serv>
Mar 09 23:47:45 localhost.localdomain systemd[1]: Started nginx - high performance web serve>

Opening the firewall

To allow access to the NGINX service, configure the firewall accordingly.

This ensures that incoming traffic can reach the web server.

1
2
3
4
[root@localhost ~]# firewall-cmd --add-service=http --permanent
success
[root@localhost ~]# firewall-cmd --reload
success

Visiting the test webpage

1
2
[root@localhost ~]# curl http://192.168.225.32
Hello nginx, I'm Haoyang Sun!

Gracefully reloading NGINX

To apply configuration changes without interrupting active connections, use a graceful reload.

This ensures that NGINX reloads its settings smoothly without downtime.

1
nginx -s reload

Sending the reload signal to reload the configuration files without interrupting active connections.