Practical Guide: Configuring Nginx for WordPress on Debian 13 (Trixie)

Automated English translation of the original Spanish article. Code examples keep their original identifiers.

This guide walks you through a clean, secure, and functional Nginx + PHP-FPM setup for a personal WordPress site or a modest blog on a Debian 13 server. It does not aim to be the most advanced setup on the planet (we will save that for when you get thousands of daily visits), but rather a solid, modern, and reasonably secure baseline that you can deploy to production without fear.

It is designed for those managing their own VPS or learning how to do so. Let’s get to work:

1. Prerequisites

Before starting, make sure you have:

  • A server running Debian 13 (Trixie), freshly updated (sudo apt update && sudo apt upgrade).
  • SSH access with sudo privileges.
  • A domain (or subdomain) already pointing to your server’s public IP address.

The stack we will use (everything sourced from the official Debian repositories):

  • Nginx (the latest stable version available in the repos).
  • PHP 8.3 + PHP-FPM (shipped by default in Debian 13).
  • MariaDB or MySQL (your choice; this guide won’t cover it since we assume you already have it installed).

To keep everything organized and follow standard Debian conventions, we will place WordPress here:

/var/www/wordpress
├── index.php
├── wp-config.php
├── wp-content/
└── wp-includes/

If you already have WordPress in another path, simply adjust it later in the configuration.

3. Creating the Nginx Configuration File

We will create a dedicated configuration file for your site:

sudo nano /etc/nginx/sites-available/wordpress

Copy and paste the following block. Do not forget to replace tudominio.com with your actual domain (both versions: with and without www, or just the one you use).

server {
    listen 80;
    server_name tudominio.com www.tudominio.com;

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

    # Permite subir archivos de hasta 64 MB (ajústalo si subes vídeos o temas pesados)
    client_max_body_size 64M;

    # Logs específicos para este sitio (te facilitan mucho la vida al depurar)
    access_log /var/log/nginx/wordpress_access.log;
    error_log  /var/log/nginx/wordpress_error.log;

    # Headers de seguridad básicos pero importantes
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;

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

    # Aquí se procesa todo el PHP
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }

    # Bloqueamos acceso a archivos sensibles (muy importante)
    location ~* /(wp-config\.php|readme\.html|license\.txt) {
        deny all;
    }

    # Impedimos que se ejecute código PHP dentro de la carpeta de uploads
    # (ataque muy común)
    location ~* /wp-content/uploads/.*\.php$ {
        deny all;
    }

    # Cacheamos imágenes, css, js y fuentes por 30 días
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
        expires 30d;
        access_log off;
        add_header Cache-Control "public";
    }
}

4. Enabling the Site and Testing the Configuration

# Creamos el enlace simbólico
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/

# Verificamos sintaxis (crucial antes de recargar)
sudo nginx -t

# Si dice "ok" → recargamos sin cortar conexiones
sudo systemctl reload nginx

If nginx -t returns an error, check the message: it is usually due to a missing semicolon or indentation issue.

5. Correct Permissions (This Is Crucial)

WordPress and Nginx will complain loudly if file permissions are incorrect. Set them up like this:

# Todo pertenece a www-data (usuario de Nginx/PHP-FPM en Debian)
sudo chown -R www-data:www-data /var/www/wordpress

# Directorios --> 755
sudo find /var/www/wordpress -type d -exec chmod 755 {} \;

# Archivos --> 644
sudo find /var/www/wordpress -type f -exec chmod 644 {} \;

At this point, you should be able to access the WordPress installer from your browser (http://tudominio.com).

6. HTTPS Configuration with Let’s Encrypt (Essential Nowadays)

6.1 Install Certbot

sudo apt update
sudo apt install certbot python3-certbot-nginx

6.2 Obtain and Install the Certificate

sudo certbot --nginx -d tudominio.com -d www.tudominio.com

Follow the interactive wizard. You will almost always want option 2 (redirect all HTTP traffic to HTTPS). Certbot will automatically modify your configuration file.

6.3 Minor Post-Certbot Optimization

Once Certbot finishes, open the file again (usually /etc/nginx/sites-available/wordpress) and ensure that the block listening on port 443 includes this line:

listen 443 ssl http2 on;   # http2 on --> sintaxis recomendada en versiones modernas

Or in some cases (depending on the exact Nginx version):

listen 443 ssl;
http2 on;

Save the file, test the syntax (sudo nginx -t), and reload (sudo systemctl reload nginx).

WordPress Ready to Go

And that should do it for now.

With this configuration, you have a solid Nginx + WordPress environment that is secure for daily use and easy to maintain. It is not overly optimized (it doesn’t include FastCGI caching or HTTP/3 yet), but for a personal blog, portfolio, or small project, it is more than sufficient and spares you many common headaches.

You can review the final Nginx configuration file here.

If you later need extra hardening, aggressive caching, or a multisite setup, I plan on expanding this guide. Let me know in the comments if it worked for you or if anything didn’t go as expected. Usually, it’s just a minor syntax or permission detail! Happy sysadminning.