# HTTP - Redirect to HTTPS
server {
    listen 80;
    server_name silkeprint.printxpand.net;

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

    location / {
        return 301 https://$host$request_uri;
    }
}

# HTTPS - Serve content
server {
    listen 443 ssl;
    server_name silkeprint.printxpand.net;

    root /var/www/html/pub;
    index index.php index.html index.htm;
    client_max_body_size 1024M;

    ssl_certificate /etc/letsencrypt/live/silkeprint.printxpand.net/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/silkeprint.printxpand.net/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

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

    location /node {
        rewrite ^/node(/.*)$ $1 break;
        proxy_pass http://magento-silkeprint:3000/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass magento-silkeprint:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTP_AUTHORIZATION $http_authorization;
        fastcgi_connect_timeout  3600s;
        fastcgi_send_timeout 36600s;
        fastcgi_read_timeout 3600s;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;

        fastcgi_intercept_errors on;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
    }

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