worker_processes  4;

error_log  /opt/bitnami/nginx/logs/error.log debug;
pid        /opt/bitnami/nginx/tmp/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    map $request_method $ratelimit_key {
        POST     $binary_remote_addr;
        default  "";
    }

    limit_req_zone $ratelimit_key zone=createFeed:10m rate=1r/m;

    server {
        listen              80;
        listen              [::]:80;
        http2               on;

        location /api/feed {
            limit_req zone=createFeed nodelay;
            proxy_pass http://htwkalender-ical:8091;
            client_max_body_size 20m;
            proxy_connect_timeout 600s;
            proxy_read_timeout 600s;
            proxy_send_timeout 600s;
            send_timeout 600s;
            limit_req_status 429;
        }

        location /api {
            proxy_pass http://htwkalender-data-manager:8090;
            client_max_body_size 20m;
            proxy_connect_timeout 600s;
            proxy_read_timeout 600s;
            proxy_send_timeout 600s;
            send_timeout 600s;
        }

        location /_ {
            proxy_pass http://htwkalender-data-manager:8090;
            client_max_body_size 100m;
        }

        location / {
            proxy_pass http://htwkalender-frontend:8000;
        }
    }
}
