Nginx 1.1.4+ can serve upstream connection with HTTP1.1 keepalive directive, see the official documentation (it's not the same as keepalived clients' connections). So the Unicorn configuration can look like as below:
upstream unicorn {
server unix:/tmp/unicorn.todo.sock fail_timeout=0;
keepalive 4;
}
server {
try_files $uri/index.html $uri @unicorn;
keepalive_timeout 70;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
These headers are required for HTTP connection: proxy_http_version and proxy_set_header.
So the question is the configuration valid or socket-connection is permanent by itself?
Yes, it's valid. There's no difference between UNIX-socket and TCP/IP-socket in terms of HTTP Keepalive.