nginx - persistent back-end server connections for performance

TCP open/close is expensive and limits throughput. Clients like browsers that can utilize persistent connections (keepalive) do not present a problem. IoT/M2M devices that are low power can't use persistent connections unless they utilize a gateway/proxy.

NGINX has built-in support for handling the client TCP open/close and proxying the requests over a pool of persistent back-end server connections similar to Apache's AJP, but supposedly more efficiently.

nginx configuration

tested while watching "sudo tcpdump -i 6.lo -nnvvXS port 8181" to verify that nginx indeed does not repeatedly reestablish connections between nginx and back-end server.

http {
        ....

    upstream foo_backend {
        server localhost:8181;

        # maintain a maximum of 10 idle connections to each upstream server
        keepalive 10;
    }

    server {
        listen       8080;
        server_name  localhost;

# serve anything from nginx_home/html
        location / {
            root   html;
            index  index.html index.htm;
        }

# proxy /foo/ to localhost:8181
        location /foo/ {
            proxy_pass http://foo_backend;
            proxy_http_version 1.1; # set to HTTP version to 1.1 for connection to backend
            proxy_set_header Connection ""; # clear Connection header from client
        }

Comments

Popular posts from this blog

Sites, Newsletters, and Blogs

Oracle JDBC ReadTimeout QueryTimeout

Locks held on Oracle for hours after sessions abnormally terminated by node failure