How to Set Up a Reverse Proxy with Nginx on AlmaLinux 9

A reverse proxy acts as an intermediary server, directing client requests to backend servers while offering benefits like improved load balancing, security, and caching. NGINX, known for its performance and simplicity, is ideal for setting up a reverse proxy. This guide outlines the steps to configu

Last updated 30 Nov 2026Also in: Dedicated Servers

A reverse proxy acts as an intermediary server, directing client requests to backend servers while offering benefits like improved load balancing, security, and caching. NGINX, known for its performance and simplicity, is ideal for setting up a reverse proxy. This guide outlines the steps to configure it on AlmaLinux 9.

Prerequisites

Before getting started, ensure you have:

  • A server running AlmaLinux 9 with sudo privileges.
  • NGINX installed on the server.
  • A domain name pointing to your serverโ€™s IP address.

Step 1: Update System Packages

Update your system to ensure all packages are up to date:

sudo dnf update -y

Step 2: Install NGINX

If NGINX isnโ€™t already installed, install it using the command:

sudo dnf install nginx -y

Start and enable NGINX to run at boot:

sudo systemctl start nginx
sudo systemctl enable nginx

Check the installation by visiting your serverโ€™s IP in a browser (http://<server-ip>). You should see the default NGINX page.

Step 3: Configure NGINX as a Reverse Proxy

Create a Configuration File:
Add a new NGINX configuration file for your domain:bashCopy code

sudo nano /etc/nginx/conf.d/reverse-proxy.conf

Set Up the Reverse Proxy Rules:
Add the following content to the file:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Replace example.com with your domain name and http://127.0.0.1:8080 with your backend serviceโ€™s address and port.

Test the Configuration:

Check for syntax errors:

sudo nginx -t

Reload NGINX:

Apply the configuration changes:

sudo systemctl reload nginx

Step 4: Enable SSL for Secure Connections

nstall Certbot:
Certbot automates SSL certificate generation and renewal:

sudo dnf install certbot python3-certbot-nginx -y

Obtain an SSL Certificate:

  • Run Certbot to secure your domain. Replace example.com with your actual domain name.
sudo certbot --nginx -d example.com -d www.example.com

Verify SSL Setup:

  • After successful completion, access your site using https://example.com. Certbot automatically updates your NGINX configuration to redirect HTTP traffic to HTTPS.

Set Up Auto-Renewal:

  • Add a cron job for automatic certificate renewal:
echo "0 0 * * * certbot renew --quiet" | sudo tee /etc/cron.d/certbot-renew

Step 5: Test the Reverse Proxy

  • Use your domain name in a browser (http://example.com or https://example.com).
  • Ensure requests are correctly forwarded to the backend service.

Key Benefits of Using a Reverse Proxy

  • Security: Shields backend servers from direct exposure to the internet.
  • Load Balancing: Distributes traffic across multiple servers.
  • Caching: Stores static content to improve response times.
  • Flexibility: Centralizes and simplifies traffic routing.

Conclusion

Setting up an NGINX reverse proxy on AlmaLinux 9 is a straightforward process that enhances your systemโ€™s scalability and security. By adding SSL, you further secure communication between clients and servers, ensuring a robust and efficient infrastructure.

cloud servers in kenyaservers