Install Nginx from Source on AlmaLinux 10

By Raman Kumar

Updated on Jun 12, 2025

Learn how to install and configure Nginx from source on AlmaLinux 10 in this 2025 step-by-step guide. This tutorial includes secure user setup.

Installing Nginx from source gives us full control over performance, security modules, and system paths — something that default package managers don't always allow. In this step-by-step tutorial, we’ll walk through building and configuring a secure, production-grade Nginx setup on AlmaLinux 10 from scratch.

We’re going to build it the right way — with logs, permissions, and system integration all properly handled.

Prerequisites

Before starting, make sure our new Ubuntu server is ready. The following components should be installed and configured:

How to Install Nginx from Source on AlmaLinux 10 – Step-by-Step Tutorial (2025)

Step 1: Update the System

Start by making sure our system is fully updated.

sudo dnf update -y

Step 2: Install Build Tools and Required Libraries

AlmaLinux 10 uses PCRE2, so we’ll install that along with other essential packages:

sudo dnf groupinstall "Development Tools" -y
sudo dnf install wget tar gcc make zlib zlib-devel openssl openssl-devel libpcre2 libpcre2-devel -y

These are needed to compile and support gzip, SSL, and rewrite rules.

Step 3: Create a Non-Login Nginx User

We'll create a dedicated system user for running Nginx worker processes securely:

sudo useradd --system --no-create-home --shell /sbin/nologin nginx

Step 4: Download the Latest Nginx Source Code

Find latest Nginx version on official website.

cd /usr/local/src
sudo wget https://nginx.org/download/nginx-1.28.0.tar.gz
sudo tar -zxvf nginx-1.28.0.tar.gz
cd nginx-1.28.0

You can always check nginx.org/download for the latest version.

Step 5: Configure Nginx with Essential Modules

We’re compiling Nginx with support for HTTP/2, SSL, gzip, and status monitoring.

sudo ./configure \
--user=nginx \
--group=nginx \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_stub_status_module

Notice how we're pointing everything to standard Linux paths for cleaner integration.

Step 6: Compile and Install Nginx

sudo make
sudo make install

Step 7: Set Correct Directory Structure and Permissions

We’ll now create required directories and assign proper permissions.

sudo mkdir -p /var/log/nginx
sudo mkdir -p /var/lock/nginx
sudo mkdir -p /var/cache/nginx
sudo mkdir -p /run

sudo chown -R nginx:nginx /var/log/nginx /var/lock/nginx /var/cache/nginx /etc/nginx

Step 8: Configure nginx.conf Properly

Open the main config file:

sudo nano /etc/nginx/nginx.conf

Update the top section to:

user nginx;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log warn;

events {
    worker_connections 1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
}

Also, make sure temp paths (e.g., client_body_temp_path) point to /var/cache/nginx and not /etc/nginx.

Step 9: Grant Permission to Bind to Port 80

This avoids running the entire process as root:

sudo setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx

Step 10: Create a Proper Systemd Service File

sudo nano /lib/systemd/system/nginx.service

Paste this content:

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target

[Service]
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s quit
PIDFile=/run/nginx.pid
Type=forking
Restart=on-failure

[Install]
WantedBy=multi-user.target

Then reload systemd:

sudo systemctl daemon-reexec
sudo systemctl daemon-reload

Step 11: Start and Enable Nginx

sudo systemctl start nginx
sudo systemctl enable nginx

Check status:

sudo systemctl status nginx

Step 12: Allow Traffic Through Firewall

If firewalld is enabled, run:

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

Step 13: Test the Installation

Visit your server’s IP or domain in the browser:

http://your-server-ip

You should see the default Nginx welcome page.

You can also verify via CLI:

curl http://localhost

Summary

In this tutorial, we've learnt how to install and configure Nginx from source on AlmaLinux 10. By compiling and configuring Nginx from source on AlmaLinux 10, we:

  • Gained full control over modules and paths
  • Used secure user privileges for safety
  • Integrated cleanly with systemd
  • Enabled performance features like gzip and HTTP/2
  • Avoided common permission issues with PID, logs, and ports

We’re here to make the web work faster and smarter — the right way.