v1.0

PHP 8.x + FPM (Generic)

Универсальный конфиг для PHP-приложений через FastCGI (без привязки к Laravel/WP)

Пример конфига
nginx.conf
server {
    listen 80;
    listen [::]:80;
    server_name example.com;

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

    server_tokens off;
    client_max_body_size 50m;

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

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

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

    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_param DOCUMENT_ROOT   $document_root;
        fastcgi_read_timeout 60s;
    }

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

    location ~ /\. {
        deny all;
    }

    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-mbstring php8.2-xml php8.2-curl php8.2-mysql
  2. Убедитесь что сокет PHP-FPM существует: ls /run/php/php8.2-fpm.sock
  3. Настройте права на директорию: chown -R www-data:www-data /var/www/html
  4. Запустите PHP-FPM: systemctl enable --now php8.2-fpm
  5. Скопируйте конфиг в /etc/nginx/sites-available/, проверьте (nginx -t) и перезагрузите (systemctl reload nginx)