upstream php-handler {
    server nextcloud-fpm:9000;
}

server {
    listen 80;
    server_name _;

    root /var/www/html;
    client_max_body_size 10G;
    fastcgi_buffers 64 4K;

    # Internal Docker requests may include /cloud (OVERWRITEWEBROOT) — strip it.
    location ^~ /cloud/ {
        rewrite ^/cloud/(.*)$ /$1 last;
    }

    location / {
        rewrite ^ /index.php;
    }

    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) {
        deny all;
    }

    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
        deny all;
    }

    location ~ \.php(?:$|/) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        set $path_info $fastcgi_path_info;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
    }

    location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
        try_files $uri /index.php$request_uri;
        access_log off;
    }
}
