# nginx.conf

server {
    listen 80;
    server_name scanner.local;

    keepalive_timeout       5;
    client_max_body_size    4G;

    # ---- Static
    location /static/ {
        alias /home/rpi4/PlanarianScanner/test_tube_scanner/staticfiles/;
        expires 30d;
        access_log off;
    }
    location /favicon.ico {
        alias /home/rpi4/PlanarianScanner/test_tube_scanner/staticfiles/img/logo.png;
    }

    # ---- Media
    location /media/ {
        alias /home/rpi4/PlanarianScanner/test_tube_scanner/media/;
        expires 30d;
        access_log off;
    }
    
    # ---- WebSocket
    location /ws/ {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 86400;  # Temps de timeout long pour les WebSockets
    }

    # ---- Django HTTP
    location / {
        proxy_pass http://127.0.0.1:8000;  # Port par défaut de Daphne
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;   
    }
    
    location /adminer/ {
        alias /var/www/adminer/;
        index index.php;
        
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include fastcgi_params;
        }
    }   
}


