By default, NGINX enables keep alive connections for non-proxied connections. This means that the connection between NGINX and the browser has already been optimized. However, as keepalive packets require HTTP/1.1 support, it's not enabled by default for reverse proxy connections. Using our Express example from Chapter 3, Common Frameworks, we can add the additional directives:
server { listen 80; server_name express.nginxcookbook.com; access_log /var/log/nginx/express-access.log combined; location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; keepalive 8; } }