# Matka Arena — single domain Nginx for rosematka.com
#
# Paths:
#   /         → player
#   /admin/   → admin
#   /api/     → PHP backend (api.php)
#
# VPS folders expected:
#   /var/www/matka/player
#   /var/www/matka/admin
#   /var/www/matka/api     ← contents of deploy/upload/api/

server {
    listen 80;
    listen [::]:80;
    server_name rosematka.com www.rosematka.com;

    # After certbot, HTTPS server block will be added automatically.
    # Or use: certbot --nginx -d rosematka.com -d www.rosematka.com

    client_max_body_size 20M;

    # -------- Player: / --------
    root /var/www/matka/player;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }

    # -------- Admin: /admin/ --------
    location = /admin {
        return 301 /admin/;
    }

    location /admin/ {
        alias /var/www/matka/admin/;
        index index.html;
        try_files $uri $uri/ @admin_spa;
    }

    location @admin_spa {
        rewrite ^ /admin/index.html last;
    }

    # -------- API: /api/ --------
    # Files live in /var/www/matka/api/ so /api/api.php maps cleanly.
    location = /api {
        return 301 /api/;
    }

    location /api/ {
        alias /var/www/matka/api/;
        index api.php;

        location ~ ^/api/(.+\.php)$ {
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /var/www/matka/api/$1;
            fastcgi_param SCRIPT_NAME /api/$1;
            # Change socket if your PHP version differs (ls /run/php/)
            fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        }
    }

    location ~ /\. {
        deny all;
    }
}
