# Replace paths, host name, certificate paths, and the PHP-FPM socket.
server {
    listen 80;
    listen [::]:80;
    server_name ams.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name ams.example.com;

    root /var/www/powerams/current/public;
    index index.php;
    client_max_body_size 10m;

    ssl_certificate /etc/letsencrypt/live/ams.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ams.example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_session_timeout 1d;
    ssl_session_cache shared:POWERAMS_SSL:10m;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

    access_log /var/log/nginx/powerams-access.log;
    error_log /var/log/nginx/powerams-error.log warn;

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

    location = /index.php {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        fastcgi_param HTTPS on;
        fastcgi_param HTTP_PROXY "";
        fastcgi_pass unix:/run/php/php8.2-fpm-powerams.sock;
        fastcgi_read_timeout 60s;
    }

    location ~ \.php$ { return 404; }
    location ~ /\. { deny all; }
    location ~* ^/(?:app|bootstrap|config|database|resources|routes|storage|tests|deployment|docs)/ { deny all; }

    location ~* \.(?:css|js|png|jpg|jpeg|ico)$ {
        expires 7d;
        add_header Cache-Control "public, max-age=604800, immutable";
        try_files $uri =404;
    }
}
