server {
    listen 8080;
    server_name _;

    client_max_body_size 16m;
    index index.php;

    location = / {
        return 302 /app/androidcast_project/crashes/;
    }

    location = /app/androidcast_project/graphs {
        return 302 /app/androidcast_project/graphs/;
    }

    location ^~ /app/androidcast_project/graphs/assets/ {
        alias /workspace/examples/crash_reporter/backend/public/assets/;
    }

    location = /app/androidcast_project/graphs/api/graphs.php {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /workspace/examples/crash_reporter/backend/public/api/graphs.php;
        fastcgi_param SCRIPT_NAME /app/androidcast_project/graphs/api/graphs.php;
        fastcgi_param DOCUMENT_ROOT /workspace/examples/crash_reporter/backend/public;
        fastcgi_pass crash-php:9000;
        fastcgi_read_timeout 120s;
    }

    location = /app/androidcast_project/graphs/api/graph_upload.php {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /workspace/examples/crash_reporter/backend/public/api/graph_upload.php;
        fastcgi_param SCRIPT_NAME /app/androidcast_project/graphs/api/graph_upload.php;
        fastcgi_param DOCUMENT_ROOT /workspace/examples/crash_reporter/backend/public;
        fastcgi_pass crash-php:9000;
        client_max_body_size 4m;
        fastcgi_read_timeout 120s;
    }

    location ^~ /app/androidcast_project/graphs/ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /workspace/examples/crash_reporter/backend/public/index.php;
        fastcgi_param SCRIPT_NAME /app/androidcast_project/graphs/index.php;
        fastcgi_param REQUEST_URI $request_uri;
        fastcgi_param DOCUMENT_ROOT /workspace/examples/crash_reporter/backend/public;
        fastcgi_pass crash-php:9000;
        fastcgi_read_timeout 120s;
    }

    location /app/androidcast_project/crashes/ {
        alias /workspace/examples/crash_reporter/backend/public/;
        index index.php;
        try_files $uri $uri/ @crashes_front;
    }

    location @crashes_front {
        rewrite ^ /app/androidcast_project/crashes/index.php?$query_string last;
    }

    location ~ ^/app/androidcast_project/crashes/(.+\.php)$ {
        alias /workspace/examples/crash_reporter/backend/public/$1;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /workspace/examples/crash_reporter/backend/public/$1;
        fastcgi_param SCRIPT_NAME /app/androidcast_project/crashes/$1;
        fastcgi_param DOCUMENT_ROOT /workspace/examples/crash_reporter/backend/public;
        fastcgi_pass crash-php:9000;
        fastcgi_read_timeout 120s;
    }

    location ~ /\. {
        deny all;
    }
}
