worker_processes auto;
pid /run/nginx/nginx.pid;
events { worker_connections 1024; }

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    sendfile on;
    server_tokens off;
    client_max_body_size 50m;
    access_log /dev/stdout;
    error_log /dev/stderr warn;

    gzip on;
    gzip_types text/css application/javascript application/json image/svg+xml text/plain application/xml;

    # Trust Caddy in front for the visitor's real IP address.
    set_real_ip_from 10.0.0.0/8;
    set_real_ip_from 172.16.0.0/12;
    set_real_ip_from 192.168.0.0/16;
    real_ip_header X-Forwarded-For;

    server {
        listen 8080 default_server;
        root /var/www/html/public;
        index index.php;

        add_header X-Content-Type-Options "nosniff" always;
        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header Referrer-Policy "strict-origin-when-cross-origin" always;
        add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;

        # Hashed build files and uploaded images can be cached for a long time.
        location /build/ { expires 1y; add_header Cache-Control "public, immutable"; try_files $uri =404; }
        location /assets/ { expires 30d; add_header Cache-Control "public"; try_files $uri =404;
            location ~* \.(php|phtml|phar)$ { deny all; } }

        location ~ /\.(?!well-known) { deny all; }

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

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
            fastcgi_read_timeout 120;
        }
    }
}
