server {
    listen [::]:80;
    listen 80;
    server_name ${NGINX_SERVER_NAME};
    return 301 https://$host$request_uri;
}

server {
    listen [::]:443 ssl;
    listen 443 ssl;
    http2  on;
    server_name ${NGINX_SERVER_NAME};

    root /app;
    index index.php;
    charset utf-8;

    ssl_certificate /etc/nginx/ssl/live/${APP_HOST}/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/live/${APP_HOST}/privkey.pem;

    gzip on;
    gzip_comp_level 5;
    gzip_disable "msie6";
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml application/wasm application/octet-stream;

    add_header X-Frame-Options "ALLOWALL";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    # add_header Access-Control-Allow-Origin *;
    add_header X-Request-ID $request_id;

    client_max_body_size 100m;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass ${COMPOSE_PROJECT_NAME}.php-fpm:9000;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

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

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log timings;
}
