v1.0

WordPress

Оптимизированный nginx для WordPress с PHP-FPM. Включает защиту wp-login.php от брутфорса отдельным rate-limit, блокировку xmlrpc.php, запрет выполнения PHP из uploads, и кэширование статических ресурсов.

Пример конфига
nginx.conf
limit_req_zone $binary_remote_addr zone=wp_general:10m rate=60r/m;
limit_req_zone $binary_remote_addr zone=wp_login:10m   rate=5r/m;

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

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com www.example.com;

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

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;

    server_tokens off;
    client_max_body_size 64m;

    access_log /var/log/nginx/wordpress-access.log combined;
    error_log  /var/log/nginx/wordpress-error.log warn;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;

    gzip on;
    gzip_comp_level 5;
    gzip_types text/plain text/css application/json application/javascript image/svg+xml;

    location / {
        limit_req zone=wp_general burst=20 nodelay;
        try_files $uri $uri/ /index.php?$args;
    }

    # Жёсткий лимит на страницу входа
    location = /wp-login.php {
        limit_req zone=wp_login burst=3 nodelay;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # Блокируем xmlrpc.php — частый вектор атак
    location = /xmlrpc.php {
        deny all;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_read_timeout 60s;
    }

    # Запрет выполнения PHP из папки uploads
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }

    location ~* \.(jpg|jpeg|gif|png|ico|css|js|woff2|svg)$ {
        expires 30d;
        add_header Cache-Control "public, immutable";
        access_log off;
    }

    location ~ /\.(env|git|htaccess) { deny all; }
    location = /wp-config.php { deny all; }

    error_page 404 /index.php;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html { root /usr/share/nginx/html; }
}
Как настроить
  1. Установите PHP-FPM и расширения: apt install php8.2-fpm php8.2-mysql php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip
  2. Настройте права на директорию WordPress: chown -R www-data:www-data /var/www/wordpress
  3. В wp-config.php добавьте: define('FORCE_SSL_ADMIN', true);
  4. Убедитесь что PHP-FPM запущен: systemctl status php8.2-fpm
  5. Скопируйте конфиг в nginx — обратите внимание на два server_name (www и без www)
  6. После активации проверьте что xmlrpc.php возвращает 403: curl -I https://example.com/xmlrpc.php