大网数据广告活动
服务器运维问答

Nginx keepalive when using a UNIX socket

· 52CE 我爱测

Is there any benefit or performance gain when using keepalive on an upstream that is using a UNIX socket as a server, for example: upstream test { server unix:/tmp/test.sock; keepalive 60; } server { listen 80 default_server; lis…

问题原文

原帖链接 · nbari · CC BY-SA 4.0

Is there any benefit or performance gain when using keepalive on an upstream that is using a UNIX socket as a server, for example:

upstream test {
    server unix:/tmp/test.sock;
    keepalive 60;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;

    location / {
        proxy_pass http://test;
        proxy_http_version 1.1;  
        proxy_redirect off;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

From my understanding when using a UNIX socket there is no TCP three-way handshake so the keepalive 60; in the example don't apply, is this correct?

社区高分解答

原帖链接 · danblack · CC BY-SA 4.0

UNIX sockets are still connections so the nginx keepalive is a cache of these, and it doesn't matter what happens at the lower levels.

keepalive here isn't the same as many other tools/services where those implies something is sent/received to maintain the connection.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-09-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。