# Defines the group of servers to which NGINX will proxy requests.
# NGINX will cycle through these servers in a round-robin fashion by default.
worker_processes auto;

http {
    access_log off;
    upstream backend_servers {
        {% for frontend_host in frontend_hosts %}
        server {{ frontend_host }}:8000;
        {% endfor %}
    }

    # The main server block that listens for incoming traffic.
    server {
        listen 8000; # Listen on port 8000 for incoming HTTP requests.

        location / {
            # Pass the request to the upstream group defined above.
            proxy_pass http://backend_servers;

            proxy_buffering off;
            proxy_read_timeout 24h;
            proxy_send_timeout 24h;
        }
    }
}

events {

    #
    # Determines how many clients will be served by each worker process.
    # (Max clients = worker_connections * worker_processes)
    # Should be equal to `ulimit -n / worker_processes`
    #
    worker_connections 65535;

    #
    # Let each process accept multiple connections.
    # Accept as many connections as possible, after nginx gets notification
    # about a new connection.
    # May flood worker_connections, if that option is set too low.
    #
    multi_accept on;

    #
    # Preferred connection method for newer linux versions.
    # Essential for linux, optmized to serve many clients with each thread.
    #
    use epoll;
}
