Setting Up Ratals on Nginx (Complete Configuration Guide)

Rob Cuppett Author: Rob Cuppett

If you're installing Ratals on an Nginx server, there's one important step you cannot skip: configuring your Nginx server correctly.

Unlike Apache, Nginx does not use .htaccess files, which means rewrite rules and routing must be defined manually in your server configuration.

This guide walks you through:

  1. Understand the Configuration
  2. Update Your Admin URL Path (IMPORTANT)
  3. Apply the Configuration via SSH
  4. Test Your Nginx Configuration Before Restarting
  5. Restart Services
  6. Final Notes
  7. You're Done

Step 1: Understand the Configuration

Below is a full Nginx configuration template for Ratals.

Before applying this to your server, review and update the top section to match your environment, and create a backup of your current configuration in case you need to revert.

What you need to update:

  • Root directory
    Example: /var/www/html
    Change this if your project is located elsewhere
  • PHP version socket
    Example: php8.2-fpm.sock
    Make sure this matches your installed PHP version
  • Server name
    Replace _ with what your current configuration is using

Your current server configuration file will already include most of these settings, so in many cases you can simply copy the existing values into this template and adjust them where needed to match your environment.

Nginx Configuration Template

server {
    ############################################################
    ################## YOUR CORE SERVER SETUP ##################
    ############################################################
    
    # LISTEN PORT
    listen 80 default_server;
    listen [::]:80 default_server;
    
    # ROOT DIRECTORY (UPDATE IF NEEDED)
    root /var/www/html;
    
    # DEFAULT INDEX FILES
    index index.php index.html index.htm;
    
    server_name _;
    
    ############################################################
    # PHP HANDLER (UPDATE PHP VERSION IF NEEDED)
    ############################################################
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    }
    
    
    ############################################################
    ################# RATALS CORE SERVER SETUP #################
    ############################################################
    
    ############################################################
    # IMPORTANT:
    # Replace "YOUR_ADMIN_URL_PATH" with your admin URL path.
    #
    # Example:
    # https://yourdomain.com/backend-login/
    # Replace "YOUR_ADMIN_URL_PATH" below in all place with: backend-login
    ############################################################

    ############################################################
    # IMPORTANT:
    # If you change your admin URL inside Ratals admin area,
    # you must update it here as well.
    ############################################################
    
    ############################################################
    # GZIP COMPRESSION
    ############################################################
    gzip on;
    gzip_types text/plain text/css text/xml application/xml application/json application/javascript image/svg+xml;
    
    ############################################################
    # CACHE CONTROL
    ############################################################    
    location ~* ^/(?!admin/|YOUR_ADMIN_URL_PATH/).*\.(jpg|jpeg|png|gif|svg|ico|webp|avif|bmp|css|js|woff|woff2|ttf|otf|eot)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }
    
    ############################################################
    # DENY ACCESS TO SENSITIVE FILES
    ############################################################
    location ~* (\.htaccess|\.user\.ini)$ {
        deny all;
    }
    
    ############################################################
    # BLOCK CORE DIRECTORIES
    ############################################################
    location ~* ^/(core|hooks|storage)(/|$) {
        deny all;
    }
    
    ############################################################
    # ADMIN VIRTUAL URL
    ############################################################
    
    # Redirect /admin-path to /admin-path/
    location = /YOUR_ADMIN_URL_PATH {
        return 301 /YOUR_ADMIN_URL_PATH/;
    }
    
    # Virtual /admin-path/ URL to real /admin/
    location ^~ /YOUR_ADMIN_URL_PATH/ {
        rewrite ^/YOUR_ADMIN_URL_PATH/?(.*)$ /admin/$1 last;
        #last;
    }
    
    # ADMIN ROUTING
    location /admin/ {
       try_files $uri $uri/ /admin/index.php?$query_string;
    }
    
    ############################################################
    # ADMIN WHITELIST (REQUIRED FOR AJAX / ASSETS)
    ############################################################
    location ~* ^/admin/cms/includes/admin-fields/ajax/.*\.php$ { allow all; }
    location ~* ^/admin/cms/includes/editor/editor\.js$ { allow all; }
    location ~* ^/admin/cms/includes/notices/(ajax\.php|start-update\.php|update\.php|update-progress\.php|unset-progress-session\.php)$ { allow all; }
    location ~* ^/admin/cms/includes/media-popup-ajax\.php$ { allow all; }
    location ~* ^/admin/cms/includes/stylesheet\.css$ { allow all; }
    location ~* ^/admin/cms/layouts/(static|table)/ajax/.*\.php$ { allow all; }
    location ~* ^/admin/commerce/layouts/(static|table)/ajax/.*\.php$ { allow all; }
    location ~* ^/admin/erp/includes/admin-fields/ajax/.*\.php$ { allow all; }
    location ~* ^/admin/erp/layouts/(static|table)/ajax/.*\.php$ { allow all; }
    
    ############################################################
    # BLOCK DIRECT ACCESS TO ADMIN MODULES
    ############################################################
    location ~* ^/admin/(cms|commerce|erp|ai)(/|$) {
        deny all;
    }
    
    ############################################################
    # MAIN SITE ROUTING
    ############################################################
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
}

Step 2: Update Your Admin URL Path (IMPORTANT)

Inside the configuration, you will see this placeholder:

YOUR_ADMIN_URL_PATH

You must replace this in all 5 locations with your actual admin URL path.

Example:

If your admin URL is:

https://www.ratals.com/backend-login/

Then replace:

YOUR_ADMIN_URL_PATH

With:

backend-login

Why this matters:

  • Keeps your admin area secure (not using default /admin)
  • Ensures routing works correctly
  • Prevents broken admin URLs and login issues

If you ever change your admin URL inside Ratals later, you must update it here as well.

Step 3: Apply the Configuration via SSH

Once your file is ready, connect to your server via SSH and follow these steps.

Open your Nginx config file:

nano /etc/nginx/sites-available/default

Paste your configuration

  • Replace the existing contents with your updated config - make sure you have updated the template above with your current server configuration values

Save and exit:

CTRL + O is how you Save (Write Out)
Press Enter to confirm the save
CTRL + X to Exit the nano edit screen

Step 4: Test Your Nginx Configuration Before Restarting

Before restarting anything, always test:

sudo nginx -t

If everything is correct, you'll see a success message.

Step 5: Restart Services

Apply your changes by restarting PHP and Nginx:

sudo systemctl restart php8.2-fpm
sudo systemctl restart nginx

Final Notes

  • If something doesn't load correctly, it's usually:
    • Incorrect admin path replacement
    • Wrong PHP version socket
    • Wrong root directory
  • Nginx is strict — even a small typo can break the config, so always run:
    sudo nginx -t

You're Done

Once everything is configured and restarted:

  1. Go back to your Ratals install page
  2. Refresh the page - the Nginx message will still appear, which is expected
  3. Continue the installation
  4. Important - Enter the admin backend URL you configured here as your admin URL during the installation. They must match for everything to work correctly.
Rob Cuppett
About the Author
Rob Cuppett is the founder and lead engineer behind Ratals, bringing over 20 years of experience in digital marketing, software development, and business automation. He shares expert tutorials, practical guides, and insights to help business owners optimize, customize, and fully leverage software solutions to grow their businesses efficiently.
0 Comments
Post a New Comment
This site uses cookies to deliver its services and to analyze traffic. Learn more on our Cookie Policy and Privacy Policy.