Tutorials  /  Linux Basics

How to Install and Configure Nginx on AlmaLinux 9

Ccentron Redaktion · August 2025 ·8 min read ·Linux Basics, Tutorial

Nginx is a high-performance, open-source web server that functions as a reverse proxy, load balancer, and HTTP cache. To deploy it on a stable enterprise-grade platform, you can install Nginx Web Server on AlmaLinux 9. It easily handles static and dynamic content and works well with technologies such as PHP and database servers.

In this article, you'll learn how to install and configure Nginx on AlmaLinux 9. The steps include installing Nginx, managing the system service, setting up a custom server block (virtual host), and enabling HTTPS with Let's Encrypt.

Prerequisites

Before you begin, you need to:

  • Have access to an AlmaLinux 9 instance as a non-root user with sudo privileges.
VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Install Nginx on AlmaLinux 9

You can install Nginx on AlmaLinux from the default DNF package sources. It's available using the nginx package name. Use the following steps to update the DNF package manager and install Nginx.

Update system packages

Console
$ sudo dnf update

Install the Nginx web server

Console
$ sudo dnf install nginx -y

Check that Nginx is installed correctly

Console
$ sudo nginx -v

Output:

Console
nginx version: nginx/1.20.1

Start the Nginx service

Console
$ sudo systemctl start nginx

Enable HTTP traffic in the firewall

Console
$ sudo firewall-cmd --permanent --add-service=http

Run the following command to install Firewalld if it's not installed and allow SSH connections

Console
$ sudo dnf install firewalld -y && sudo firewall-cmd --permanent --add-service=ssh

Start Firewalld if it's not running

Console
$ sudo systemctl start firewalld

Apply firewall changes

Console
$ sudo firewall-cmd --reload

Verify that Nginx is working in a browser

http://server-ip-address

Manage the Nginx System Service

Nginx installs a systemd service by default. Use the following steps to manage the service and ensure it runs consistently on your server.

Enable Nginx to start on boot

Console
$ sudo systemctl enable nginx

Start Nginx if it isn't already running

Console
$ sudo systemctl start nginx

Verify the Nginx system service and confirm that it's running

Console
$ sudo systemctl status nginx

Output:

Console
● nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: disabled)
     Active: active (running) since Sun 2025-03-30 23:12:44 UTC; 1min 33s ago
   Main PID: 52297 (nginx)
      Tasks: 2 (limit: 5716)
     Memory: 2.0M
        CPU: 36ms
     CGroup: /system.slice/nginx.service
             ├─52297 "nginx: master process /usr/sbin/nginx"
             └─52298 "nginx: worker process"

Reload Nginx to apply new configuration changes

Console
$ sudo systemctl reload nginx

Restart the Nginx service

Console
$ sudo systemctl restart nginx

Create Nginx Virtual Host Configurations (Server Blocks)

Nginx virtual host configurations include the server name, administrator, and the backend web application information. The default.d and conf.d directories contain virtual host configurations for Nginx on AlmaLinux by default unless changed. Follow these steps to create a custom server block with your own HTML content.

Verify the Nginx system service and confirm that it's running

Console
$ sudo systemctl status nginx

Set up the document root and create sample content

Console
$ sudo mkdir /usr/share/nginx/example && sudo nano /usr/share/nginx/example/index.html

Enter the following HTML application code in the index.html file

Sample HTML Application

Powered by the Nginx Web Server

Create a new server block file

Console
$ cd /etc/nginx/conf.d/ &&  sudo nano example-host.conf

Enter the following Nginx configurations into the example-host.conf file. Replace example.com with your domain

INI
server {
    listen       80;
    listen       [::]:80;
    server_name  example.com;

    root         /usr/share/nginx/example;
    index        index.html index.htm;

    access_log   /var/log/nginx/example.com_access.log;
    error_log    /var/log/nginx/example.com_error.log;

    location / {
        try_files $uri $uri/ =404;
    }
}

Test the Nginx configuration syntax for errors

Console
$ sudo nginx -t

Output:

Console
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload Nginx to apply the configuration changes

Console
$ sudo systemctl reload nginx

Test access to your domain and confirm that the web application loads

http://your-domain.com/

Secure the Nginx Web Server

Nginx delivers web applications using HTTP by default unless specified in your virtual host configurations. HTTPS provides encryption between the Nginx and a client's web browser, ensuring secure connections to the web server. This section walks you through installing Certbot, configuring HTTPS, and adjusting SELinux and firewall settings.

Install the EPEL repository, which includes the Certbot tool

Console
$ sudo dnf install epel-release -y

Update your system packages

Console
$ sudo dnf update

Install Certbot with Nginx plugin support

Console
$ sudo dnf install python3-certbot-nginx -y

Request an SSL certificate using Certbot. Replace example.com and admin@example.com with your actual domain and email address

Console
$ sudo certbot --nginx --domain example.com --email admin@example.com --agree-tos

Note: Replace example.com with your real domain name. If you don't have one, consider using a test domain or skip the SSL setup.

Reload Nginx to apply the HTTPS configuration

Console
$ sudo systemctl reload nginx

Test the Nginx configuration for syntax errors

Console
$ sudo nginx -t

Output:

Console
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Allow HTTPS traffic through the firewall

Console
$ sudo firewall-cmd --permanent --add-service=https

Optionally, remove HTTP access if you want to enforce HTTPS-only

Console
$ sudo firewall-cmd --permanent --remove-service=http

Reload Firewalld to apply the new rules

Console
$ sudo firewall-cmd --reload

Check the status of SELinux to ensure it's enabled

Console
$ sestatus

Output:

Console
SELinux status:                 enabled

Install the required SELinux management utilities for the semanage command

Console
$ sudo dnf install policycoreutils-python-utils -y

This ensures the semanage tool is available to manage SELinux contexts

Update SELinux file context rules, enabling Nginx to read files in your custom directory

Console
$ sudo semanage fcontext -a -t httpd_sys_content_t "/usr/share/nginx/example(/.*)?"

Apply the new SELinux context

Console
$ sudo restorecon -Rv /usr/share/nginx/example/

Output:

Console
Relabeled /usr/share/nginx/example from unconfined_u:object_r:usr_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
Relabeled /usr/share/nginx/example/index.html from unconfined_u:object_r:usr_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0

Access your domain in a web browser using HTTPS to verify that the certificate is working

https://example.com

Conclusion

You’ve now set up Nginx on AlmaLinux 9, configured it to serve static web content, and secured it with HTTPS and SELinux rules. Nginx is a flexible and high-performance web server that can easily scale to support dynamic web apps, backend integrations like PHP or databases, and production-grade deployments. From here, you can extend your setup by adding reverse proxy rules, enabling load balancing, or integrating with application stacks like Laravel, Flask, or Node.js.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren