Nginx is a free, open-source software solution for web serving, reverse proxying, caching, load balancing, media streaming, and more. Compared to Apache, Nginx is a high‑performance, highly scalable, and highly available web server. Thanks to its ability to handle massive numbers of connections, it is the preferred web server of many websites that deal with high traffic.
By default, the latest Nginx mainline version is not included in the Rocky Linux Appresteam repository. For a production environment, it is always recommended to install the latest version.
In this post, we will show you how to install the latest Nginx Mainline on Rocky Linux 8.
Step 1 – Add an Nginx Repository
First, install the dnf-utils package using the following command:
dnf install dnf-utils -y
Next, create an Nginx repo with the following command:
nano /etc/yum.repos.d/nginx.repo
Add the following lines:
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
Save and close the file, then enable the Nginx Mainline repo using the following command:
yum-config-manager --enable nginx-mainline
Step 2 – Install Nginx Mainline on Rocky Linux 8
Now, run the following command to install the latest Nginx Mainline package to your server.
dnf install nginx
You should see the following output:
nginx stable repo 48 kB/s | 32 kB 00:00 nginx mainline repo 111 kB/s | 86 kB 00:00 Dependencies resolved. =============================================================================================================================================== Package Architecture Version Repository Size =============================================================================================================================================== Installing: nginx x86_64 1:1.21.3-1.el8.ngx nginx-mainline 823 k Transaction Summary =============================================================================================================================================== Install 1 Package Total download size: 823 k Installed size: 2.8 M Is this ok [y/N]: y
Once Nginx is installed, start the Nginx service and enable it to start at system reboot:
systemctl start nginx systemctl enable nginx
Next, verify the status of Nginx with the following command:
systemctl status nginx
You should get the following output:
● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2021-10-29 14:01:05 UTC; 14s ago Docs: http://nginx.org/en/docs/ Process: 4996 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS) Main PID: 4997 (nginx) Tasks: 2 (limit: 11411) Memory: 1.9M CGroup: /system.slice/nginx.service ├─4997 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf └─4998 nginx: worker process Oct 29 14:01:05 RockyLinux8 systemd[1]: Starting nginx - high performance web server... Oct 29 14:01:05 RockyLinux8 systemd[1]: nginx.service: Can't open PID file /var/run/nginx.pid (yet?) after start: No such file or directory Oct 29 14:01:05 RockyLinux8 systemd[1]: Started nginx - high performance web server.
Now, verify the Nginx version using the following command:
nginx -v
You should see the Nginx version in the following output:
nginx version: nginx/1.21.3
Step 3 – Configure Firewall
By default, Nginx listens on ports 80 and 443. If any firewall is installed and configured on your server, then you will need to allow both ports via firewalld. You can allow them with the following command:
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https
Next, reload firewalld to apply the changes:
firewall-cmd --reload
Step 4 – Access Nginx Default Page
Now, open your web browser and access the Nginx default page using the URL http://your-server-ip. You should see the Nginx default page on the following screen:
Conclusion
In the above post, we explained how to install the latest Nginx mainline version to Rocky Linux 8. You can now easily update your current Nginx version to the latest version; try it on VPS hosting from Atlantic.Net!