server {
    client_max_body_size 64M;
    listen 443 ssl;
    http2 on;
    server_name example.de;
    ssl_certificate /etc/letsencrypt/live/example.de/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.de/privkey.pem;

    gzip on;
    gzip_comp_level 6;
    gzip_min_length 256;
    gzip_vary on;
    gzip_proxied any;
    gzip_types
        text/css
        text/javascript
        application/javascript
        application/x-javascript
        application/json
        application/xml
        image/svg+xml;

    index index.html;
    root /example/dist;

    error_log logs/error.log info;
    access_log logs/access.log combined;

    location /socket.io/ {
        proxy_pass http://localhost:9303/socket.io/;
        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;

        proxy_connect_timeout 3600s;
        proxy_send_timeout 3600s;
        proxy_read_timeout 3600s;
        send_timeout 3600s;

        proxy_buffering off;
        proxy_cache off;

        keepalive_timeout 65;
        keepalive_requests 100;
    }

    location /api/ {
        proxy_pass http://localhost:9303/api/;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_set_header User-Agent $http_user_agent;
        proxy_set_header Content-Type $content_type;
        proxy_set_header Content-Length $content_length;

        proxy_set_header X-API-Key $http_x_api_key;

        proxy_connect_timeout 30s;
        proxy_send_timeout 30s;
        proxy_read_timeout 30s;
        proxy_buffering off;

        client_max_body_size 10M;
    }

    location ^~ /Kategorie/ {
        types {}
        default_type text/html;
    }

    location ^~ /Artikel/ {
        types {}
        default_type text/html;
    }

    location = /sitemap.xml {
        types {}
        default_type application/xml;
    }

    location ~ ^/(datenschutz|impressum|batteriegesetzhinweise|widerrufsrecht|sitemap|agb|Kategorien|Konfigurator|404|profile|resetPassword|thc-test|linkTelegram|filiale|aktionen|presseverleih|payment/success)(/|$) {
        types {}
        default_type text/html;
    }

    location = /404 {
        error_page 404 =404 /404-big.html;
        return 404;
    }

    location = /404-big.html {
        internal;
        alias /home/seb/src/growheads_de/dist/404;
        default_type text/html;
    }

    error_page 404 /404.html;

    location = /404.html {
        internal;
        default_type text/html;
        return 404 '<!doctype html><html><body>
            <script>
                if (!navigator.userAgent.includes("bot")) { location.href="/404"; }
            </script>
        </body></html>';
    }

    location ~* \.(js|css)\?.*$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
        add_header Vary Accept-Encoding;
    }

    location ~* \.(js|css)$ {
        if ($uri ~ "\.[a-f0-9]{7,}\.(js|css)$") {
            expires 1y;
            add_header Cache-Control "public, immutable";
            break;
        }
        expires 1d;
        add_header Cache-Control "public";
        add_header Vary Accept-Encoding;
    }

    location ~* \.(ttf|otf|woff|woff2|eot)$ {
        expires 1y;
        add_header Cache-Control "public";
        add_header Access-Control-Allow-Origin "*";
    }

    location ~* \.(jpg|jpeg|png|gif|ico|svg|webp)$ {
        expires 1y;
        add_header Cache-Control "public";
        add_header Vary Accept-Encoding;
    }

    location = /prerender.css {
        expires 1w;
        add_header Cache-Control "public";
        add_header Vary Accept-Encoding;
    }

    location /assets/ {
        expires 1y;
        add_header Cache-Control "public";
        add_header Vary Accept-Encoding;
    }
}
