# Inner VM nginx — crash reporter (no symlinks).
#
# Canonical disk paths on Alpine BE:
#   .../androidcast_project/android_cast/examples/crash_reporter/backend/public
#
# URL prefix (config.php base_path):
#   /app/androidcast_project/crashes
#
# Use the same location blocks on listen 80 and 443 if the FE proxy uses :80.

server {
    listen 443 ssl;
    server_name apps.f0xx.org artc0.intra.raptor.org;

    ssl_certificate     "/etc/letsencrypt/archive/apps.f0xx.org/fullchain1.pem";
    ssl_certificate_key "/etc/letsencrypt/archive/apps.f0xx.org/privkey1.pem";

    access_log /var/log/nginx/apps.intra.raptor.org.access_log main;
    error_log  /var/log/nginx/apps.intra.raptor.org.error_log warn;

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

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

    location = /app/androidcast_project {
        return 301 /app/androidcast_project/;
    }

    location = /app/androidcast_project/index.php {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm.socket;
        fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/index.php;
        fastcgi_param SCRIPT_NAME /app/androidcast_project/index.php;
    }

    location = /app/androidcast_project/ {
        rewrite ^ /app/androidcast_project/index.php last;
    }

    location /app/androidcast_project/ {
        alias /var/www/localhost/htdocs/apps/app/androidcast_project/;
        index index.php index.html;
        try_files $uri $uri/ =404;
    }

    location ^~ /app/androidcast_project/crashes/assets/ {
        alias /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/assets/;
    }

    location = /app/androidcast_project/crashes/api/upload.php {
        # Decompress gzip uploads from Android before PHP (needs ngx_http_gunzip_module).
        gunzip on;
        gunzip_types application/json;
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm.socket;
        fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/api/upload.php;
        fastcgi_param SCRIPT_NAME /app/androidcast_project/crashes/api/upload.php;
        fastcgi_param REQUEST_URI $request_uri;
        client_max_body_size 8m;
    }

    location ^~ /app/androidcast_project/crashes/ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm.socket;
        fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/index.php;
        fastcgi_param SCRIPT_NAME /app/androidcast_project/crashes/index.php;
        fastcgi_param REQUEST_URI $request_uri;
        client_max_body_size 4m;
    }

    location = /app/androidcast_project/graphs/api/graphs.php {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm.socket;
        fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/api/graphs.php;
        fastcgi_param SCRIPT_NAME /app/androidcast_project/graphs/api/graphs.php;
        fastcgi_param REQUEST_URI $request_uri;
    }

    location = /app/androidcast_project/graphs/api/graph_upload.php {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm.socket;
        fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/api/graph_upload.php;
        fastcgi_param SCRIPT_NAME /app/androidcast_project/graphs/api/graph_upload.php;
        fastcgi_param REQUEST_URI $request_uri;
        client_max_body_size 4m;
    }

    location ^~ /app/androidcast_project/graphs/ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm.socket;
        fastcgi_param SCRIPT_FILENAME /var/www/localhost/htdocs/apps/app/androidcast_project/android_cast/examples/crash_reporter/backend/public/index.php;
        fastcgi_param SCRIPT_NAME /app/androidcast_project/graphs/index.php;
        fastcgi_param REQUEST_URI $request_uri;
        client_max_body_size 4m;
    }

    location ~ /\. {
        deny all;
    }
}
