# cat /etc/nginx/conf.d/citadel.conf 
server {
    listen 80;
    server_name citadel.msya.gov.tt;

    # --- Main Site Configuration ---
    # This is the default root for your server
    root /var/www/html;
    index index.php index.html index.htm;

    # This handles requests for your main site
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # This handles PHP requests for your main site
    location ~ \.php$ {
        # This condition prevents this block from incorrectly handling phpMyAdmin requests
        if ($request_uri ~ ^/phpmyadmin) {
            return 404;
        }
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # --- Hospitality App Configuration ---
    location /hosp {
        alias /var/www/html/hosp_2025/public;
        index index.php;

        # If file/dir doesn't exist, rewrite to index.php (Laravel routing)
        if (!-e $request_filename) {
            rewrite ^ /hosp/index.php last;
        }

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass unix:/run/php-fpm/www.sock;
            fastcgi_param SCRIPT_FILENAME $request_filename;
        }
    }
    
    # --- phpMyAdmin Configuration ---
    # This location block uses 'alias' to correctly point to the phpMyAdmin files
    location /phpmyadmin {
        alias /usr/share/phpMyAdmin/; # Correct directive
        index index.php;
        try_files $uri $uri/ /phpmyadmin/index.php?$query_string;

        # This nested location handles ONLY the PHP files inside the aliased directory
        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass unix:/run/php-fpm/www.sock;
            # Use $request_filename because 'alias' is used
            fastcgi_param SCRIPT_FILENAME $request_filename;
        }
    }

    # Deny access to sensitive phpMyAdmin directories
    location ~ ^/phpmyadmin/(sql|setup)/ {
        deny all;
    }
}