
worker_processes  4;
#worker_processes  1; # more then 1 worker is only supported with IWCP (iworkcomproto.lua)
error_log  logs/error.log;
#error_log  logs/error.log debug;

events {
    worker_connections  8192;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '[$time_local] $remote_addr $remote_port - $remote_user $scheme "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" $upstream_cache_status';
    access_log    logs/access.log  main;
    sendfile      off;
    #tcp_nopush   on;
    server_names_hash_bucket_size 128;
    gzip  on;

#   1m = +-10.000 messages
    lua_shared_dict iworkcomproto 1m;

    init_worker_by_lua_file conf/iworkcomproto.lua;

    upstream luaupstfoo {
        server 192.168.169.2:80  weight=1 fail_timeout=5;
        server 192.168.169.17:80 weight=1 fail_timeout=5;
        server 192.168.169.26:80 weight=1 fail_timeout=5 down;
        least_conn;
    }
    upstream luaupstbar {
        server 192.168.169.3:80;
    }

    server {
        listen       80;
        server_name  localhost;

        location = /upstreamcontrol {
          default_type text/html;
            content_by_lua_file conf/upstreamcontrol.lua;
        }

#       curl -i http://127.0.0.1/upstreamstatus
        location = /upstreamstatus {
            default_type text/html;
            content_by_lua_file conf/upstreamstatus.lua;
        }

#       curl -i "http://127.0.0.1/pt"
        location /pt {
            include c:/nginx/conf/proxy.conf;
            keepalive_requests 500;
            proxy_http_version 1.1;
            proxy_ignore_client_abort on;
            proxy_pass http://luaupstfoo;
        }

    } # server end

}

# nginx 1.9+ TCP load balancer
stream {
    error_log  logs/stream_error.log info;

    upstream stream_backend {
        server 192.168.169.2:80 weight=5;
        server 192.168.169.17:80 weight=5;
        least_conn;
    }

    server {
        listen     12345;
        proxy_pass stream_backend;
    }

} # stream end
