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

 

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 WordPress root directory

    index index.php index.html index.htm;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock; # Path to your PHP-FPM socket
    }

    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;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~ /(\.|wp-config.php|xmlrpc.php|wp-.*\.php|index\.php) {
        try_files $uri =404;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock; # Path to your PHP-FPM socket
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        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: