[转帖]nginx proxy_pass keepalive

nginx,proxy,pass,keepalive · 浏览次数 : 0

小编点评

Sure, here is the summary you requested: **Keepalive Configuration Parameters** * **keepalive**: Maximum number of idle connections to preserve in the cache of each worker process. * **keepalive_requests**: Maximum number of requests that can be served through one keepalive connection. * **keepalive_time**: Maximum time during which requests can be processed through one keepalive connection. * **keepalive_timeout**: Timeout during which an idle keepalive connection to an upstream server will stay open. * **ntlm**: Allows proxying requests with NTLM Authentication. **Default Values:** * **keepalive**: 1000 * **keepalive_requests**: 1000 * **keepalive_time**: 1h * **keepalive_timeout**: 60s * **ntlm**: Not applicable by default **Additional Notes:** * Keepalive connections are used to keep upstream servers connected and avoid connections dropping due to inactivity. * Using too high a number of keepalive connections can result in excessive memory usage. * NTLM authentication requires keepalive connections to be enabled on the upstream server.

正文

Syntax: keepalive connections;
Default:
Context: upstream

This directive appeared in version 1.1.4.

Activates the cache for connections to upstream servers.

The connections parameter sets the maximum number of idle keepalive connections to upstream servers that are preserved in the cache of each worker process. When this number is exceeded, the least recently used connections are closed.

It should be particularly noted that the keepalive directive does not limit the total number of connections to upstream servers that an nginx worker process can open. The connections parameter should be set to a number small enough to let upstream servers process new incoming connections as well.

 

When using load balancing methods other than the default round-robin method, it is necessary to activate them before the keepalive directive.

 

Example configuration of memcached upstream with keepalive connections:

upstream memcached_backend {
    server 127.0.0.1:11211;
    server 10.0.0.2:11211;

    keepalive 32;
}

server {
    ...

    location /memcached/ {
        set $memcached_key $uri;
        memcached_pass memcached_backend;
    }

}

 

For HTTP, the proxy_http_version directive should be set to “1.1” and the “Connection” header field should be cleared:

upstream http_backend {
    server 127.0.0.1:8080;

    keepalive 16;
}

server {
    ...

    location /http/ {
        proxy_pass http://http_backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        ...
    }
}

 

 

Alternatively, HTTP/1.0 persistent connections can be used by passing the “Connection: Keep-Alive” header field to an upstream server, though this method is not recommended.

 

For FastCGI servers, it is required to set fastcgi_keep_conn for keepalive connections to work:

upstream fastcgi_backend {
    server 127.0.0.1:9000;

    keepalive 8;
}

server {
    ...

    location /fastcgi/ {
        fastcgi_pass fastcgi_backend;
        fastcgi_keep_conn on;
        ...
    }
}

 

 

SCGI and uwsgi protocols do not have a notion of keepalive connections.

 

Syntax: keepalive_requests number;
Default:
keepalive_requests 1000;
Context: upstream

This directive appeared in version 1.15.3.

Sets the maximum number of requests that can be served through one keepalive connection. After the maximum number of requests is made, the connection is closed.

Closing connections periodically is necessary to free per-connection memory allocations. Therefore, using too high maximum number of requests could result in excessive memory usage and not recommended.

 

Prior to version 1.19.10, the default value was 100.

 

Syntax: keepalive_time time;
Default:
keepalive_time 1h;
Context: upstream

This directive appeared in version 1.19.10.

Limits the maximum time during which requests can be processed through one keepalive connection. After this time is reached, the connection is closed following the subsequent request processing.

Syntax: keepalive_timeout timeout;
Default:
keepalive_timeout 60s;
Context: upstream

This directive appeared in version 1.15.3.

Sets a timeout during which an idle keepalive connection to an upstream server will stay open.

Syntax: ntlm;
Default:
Context: upstream

This directive appeared in version 1.9.2.

Allows proxying requests with NTLM Authentication. The upstream connection is bound to the client connection once the client sends a request with the “Authorization” header field value starting with “Negotiate” or “NTLM”. Further client requests will be proxied through the same upstream connection, keeping the authentication context.

In order for NTLM authentication to work, it is necessary to enable keepalive connections to upstream servers. The proxy_http_version directive should be set to “1.1” and the “Connection” header field should be cleared:

upstream http_backend {
    server 127.0.0.1:8080;

    ntlm;
}

server {
    ...

    location /http/ {
        proxy_pass http://http_backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        ...
    }
}

 

 

When using load balancer methods other than the default round-robin method, it is necessary to activate them before the ntlm directive.

 

 

This directive is available as part of our commercial subscription.

与[转帖]nginx proxy_pass keepalive 相似的内容:

[转帖]nginx proxy_pass keepalive

Syntax: keepalive connections; Default: — Context: upstream This directive appeared in version 1.1.4. Activates the cache for connections to upstream

[转帖]Nginx 反向代理地址后,session丢失,不能登录的问题

https://www.cnblogs.com/fan-yuan/p/14417255.html 设置反向代理后,session丢失无法正常登录,需按照如下格式设置即可location /aaaaa/bbbbbb { #代理跳转的路径 proxy_pass http://localhost:8080

[转帖]nginx 反向代理 URL替换方案

nginx 提供反向代理服务,日常开发过程中有时候我们需要使用nginx 作为代理服务根据url的不同去访问不同的服务器或者不同端口,如下提供两种方案。 1.直接替换location 匹配部分 1.proxy_pass的目标地址,默认不带/,表示只代理域名,url和参数部分不会变(把请求的path拼

[转帖]nginx 反向代理 URL替换方案

nginx 提供反向代理服务,日常开发过程中有时候我们需要使用nginx 作为代理服务根据url的不同去访问不同的服务器或者不同端口,如下提供两种方案。 1.直接替换location 匹配部分 1.proxy_pass的目标地址,默认不带/,表示只代理域名,url和参数部分不会变(把请求的path拼

[转帖]nginx的proxy_next_upstream使用中的一个坑

https://zhuanlan.zhihu.com/p/35803906 今天线上系统出了点问题,机房的电信出口突然不通了,原本以为能自动切换的nginx配置,居然没有生效,导致了业务告警,手工紧急处理了才解决了。 当时的设想是,如果这个服务的访问,出现了500或者超时的情况,会自动重试到下一个服

[转帖]Nginx之proxy_redirect详解

今天在做nginx反向代理apache的时候出了一点点问题,原来后端apache用的端口是8080通过反向代理后,使用wireshark抓包发现location头域数值为http://192.168.1.154:8080/wuman/ 如果把这个返回给客户端肯定是不可以的,看起来别扭而且还暴露了ap

[转帖]使用nginx的proxy_store缓存文件加速访问速度

https://www.qiansw.com/using-nginxs-proxystore-cache-file-to-accelerate-access-speed.html nginx的proxy_store可以将后端服务器的文件暂存在本地. 基于此,可以实现nginx的缓存后端服务器文件,加

[转帖]nginx的重试机制 proxy_next_upstream

https://blog.csdn.net/xiao__gui/article/details/89441162 https://zhuanlan.zhihu.com/p/35803906 https://www.cnblogs.com/powerwu/articles/9791295.html h

[转帖]nginx的重试机制 proxy_next_upstream

https://blog.csdn.net/xiao__gui/article/details/89441162 https://zhuanlan.zhihu.com/p/35803906 https://www.cnblogs.com/powerwu/articles/9791295.html h

[转帖]nginx 反向代理中proxy_set_header的含义

https://www.jianshu.com/p/cd813d68ed25 0.1212020.10.23 09:29:53字数 284阅读 9,939 1.proxy_set_header设置的请求头是传递给后端服务器的 2.ngixn反向代理中proxy_set_header的设置: prox