Nginx 1.1.4+ 可以使用 HTTP1.1 keepalive指令提供上游连接,请参阅官方文档(它与 keepalived 客户端的连接不同)。所以 Unicorn 配置如下所示:
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 "";
}
}
HTTP 连接需要这些标头:proxy_http_version和proxy_set_header。
所以问题是配置有效还是套接字连接本身是永久的?