server {
    listen 80;
    server_name financiera-test.duckdns.org 192.168.0.120;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name financiera-test.duckdns.org 192.168.0.120;
    root /var/www/financiera_app/public;
    index index.php index.html;

    ssl_certificate     /etc/ssl/certs/financiera-selfsigned.crt;
    ssl_certificate_key /etc/ssl/private/financiera-selfsigned.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    # phpMyAdmin
    location /phpmyadmin {
        root /usr/share/;
        index index.php index.html;

        location ~ ^/phpmyadmin/(.+\.php)$ {
            try_files $uri =404;
            root /usr/share/;
            fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/;
        }
    }

    # Laravel app
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_hide_header X-Powered-By;
    }

    location ~ /\.ht {
        deny all;
    }
}
