lxc-start -n srv-nginx
lxc-attach -n srv-nginx

 

Instalacja Nginx + PHP-FPM

apt update && apt install nginx php-fpm php-curl php-gd php-mbstring -y

Sprawdź wersję PHP, jaka się zainstalowała (w Debianie 13 domyślnie będzie to PHP 8.2 lub 8.3):

ls /var/run/php/

Zapamiętaj nazwę pliku, np. php8.2-fpm.sock – będzie potrzebna do Nginxa.

 

Konfiguracja Nginxa pod katalogi użytkowników (userdir)

nano /etc/nginx/sites-available/default

Zastąp lub uzupełnij sekcję server {} poniższym kodem (dopasuj wersję php w linii fastcgi_pass):

server {
    listen 80 default_server;
    listen [::]:80 default_server;

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

    server_name _;

    # Magia dla katalogów domowych uczniów: url/~username
    location ~ ^/~(?<user>[^/]+)(?<user_uri>/.*)?$ {
        alias /home/LO/$user/public_html$user_uri;
        index index.php index.html;
        autoindex on; # Pozwala uczniom widzieć listę plików, jeśli nie ma index.html

        # Obsługa PHP dla uczniów
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            # Zmień php8.2 na wersję, którą faktycznie masz w systemie:
            fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $request_filename;
        }
    }

    # Standardowa obsługa PHP dla strony głównej serwera
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    }
}

 

Restart Nginxa w kontenerze:

nginx -t && systemctl restart nginx

 

 

 

 

 

Spis treści: