Example of a Nginx configuration file with PHP-FPM to run a Joomla site:

server {
    listen 80;
    server_name example.com;

    root /var/www/html; # Path to Joomla root directory

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.4-fpm.sock; # Path to your PHP-FPM socket
        #fastcgi_pass unix:/run/php/php8.2-fpm.sock; # If using PHP 8.2
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
        expires max;
        log_not_found off;
    }
}

Make sure to replace example.com with your actual domain name, /var/www/html with the correct path to your Joomla root directory, and /run/php/php7.4-fpm.sock with the path to your PHP-FPM socket. Adjust the PHP version in the socket path (php7.4-fpm.sock) if you're using a different PHP version.

If you want to run over HTTPS:

server {
    listen 80;
    server_name example.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate /path/to/ssl_certificate.crt;
    ssl_certificate_key /path/to/ssl_certificate.key;

    root /var/www/html; # Path to Joomla root directory

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.4-fpm.sock; # Path to your PHP-FPM socket
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
        expires max;
        log_not_found off;
    }
}

In this configuration, we have two server blocks. The first server block listens on port 80 and redirects all HTTP requests to HTTPS using a 301 redirect.

The second server block listens on port 443 and handles HTTPS requests. It includes the SSL certificate and key paths that you need to replace with the actual paths to your SSL certificate and key files.

 

Save this configuration file with a suitable name (e.g., example.com.conf) in your Nginx configuration directory (usually located at /etc/nginx/conf.d/ or /etc/nginx/sites-available/). Then, restart Nginx for the changes to take effect.

Please note that this configuration assumes you have PHP-FPM and Nginx properly installed and configured on your server. Additionally, make sure you have the necessary PHP extensions installed for Joomla to function correctly.

More on this topic: