Nginx config for wordpress

server {
    listen 80;
    server_name *.rajubk.com rajubk.com;
    client_max_body_size 512M;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name *.rajubk.com rajubk.com;
    client_max_body_size 512M;

    root /var/www/html/wordpress;
    index index.php;

    # SSL parameters
    ssl_certificate /etc/letsencrypt/live/rajubk.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/rajubk.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/rajubk.com/chain.pem;

    # Log files
    access_log /var/log/nginx/sample.com.access.log;
    error_log /var/log/nginx/sample.com.error.log;

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

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

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

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

    # START Nginx Rewrites for Rank Math Sitemaps
    rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    # END Nginx Rewrites for Rank Math Sitemaps
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *