# This file is automatically generated, all manual changes will be lost upon Pod restart!
# Make you changes in the CS Panel or the relevant Website object.

user www-data;
worker_processes 1;

daemon off;

events {
    use epoll;
    worker_connections 8192;
    multi_accept on;
}

pid  /var/run/nginx.pid;

http {
    tcp_nopush on;
    tcp_nodelay on;
    types_hash_max_size 2048;
    client_max_body_size {{ .nginx.ClientMaxBodySize | default "512m" }};
    client_body_timeout 15;
    client_header_timeout 15;
    client_body_temp_path /tmp 1 2;
    client_body_buffer_size 256k;

    # Show client's IP in logs
    set_real_ip_from  127.0.0.1;
    set_real_ip_from  10.0.0.0/8;
    real_ip_header    X-Forwarded-For;
    real_ip_recursive on;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    # Special font mime types
    types {
        # Font types
        application/x-font-ttf           ttc ttf;
        application/x-font-otf           otf;
        image/avif-sequence              avifs;
        {{ .nginx.AdditionalMimeTypes | nindent 8 | default "" -}}
    }

    sendfile on;

    port_in_redirect off;

    keepalive_timeout {{ .nginx.KeepaliveTimeout | default "65s" }};

    server_tokens off;

    map $http_user_agent $auth_type {
        default "Restricted";
        ~^Go-http-client "off";
        ~^kube-probe "off";
    }

    {{ if .plugins.shortpixel_image_optimiser.enabled -}}
    # shortpixel-image-optimiser
    # https://shortpixel.com/knowledge-base/article/configure-nginx-to-transparently-serve-webp-files-when-supported/
    map $http_accept $webp_suffix {
        default "";
        "~*webp" ".webp";
    }

    map $http_accept $avif_suffix {
        default "";
        "~*avif" ".avif";
    }
    # shortpixel-image-optimiser End
    {{ end -}}

    {{ if not (eq .nginx.RateLimitEnabled false) -}}
    limit_req_status 403;
    limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
    limit_req_zone $binary_remote_addr zone=wp:10m rate=3r/s;
    {{ end -}}

    include common/headers-http.conf;
    include /etc/nginx/conf.d/*.conf;
    {{- .nginx.CustomHttpSnippet | default "" | nindent 4 -}}
}
