Stream: proxy_socket_sndbuf and proxy_socket_rcvbuf directives
Some checks are pending
buildbot / buildbot (push) Waiting to run

Similarly to "listen ... sndbuf/rcvbuf", proxy_socket_sndbuf and
proxy_socket_rcvbuf can be used to set the SO_SNDBUF and SO_RCVBUF
socket options, respectively, on upstream connections.  By default,
the values are left unchanged.

Closes: https://github.com/nginx/nginx/issues/1297
This commit is contained in:
Patrik Wall 2026-04-27 13:22:16 +02:00 • committed by Sergey Kandaurov
parent 04d118301f
commit 6ab37e105c

View file

@ -34,6 +34,8 @@ typedef struct {
ngx_flag_t half_close;
ngx_stream_upstream_local_t *local;
ngx_flag_t socket_keepalive;
size_t socket_rcvbuf;
size_t socket_sndbuf;
#if (NGX_STREAM_SSL)
ngx_flag_t ssl_enable;
@ -166,6 +168,20 @@ static ngx_command_t ngx_stream_proxy_commands[] = {
offsetof(ngx_stream_proxy_srv_conf_t, socket_keepalive),
NULL },
{ ngx_string("proxy_socket_rcvbuf"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_proxy_srv_conf_t, socket_rcvbuf),
NULL },
{ ngx_string("proxy_socket_sndbuf"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_STREAM_SRV_CONF_OFFSET,
offsetof(ngx_stream_proxy_srv_conf_t, socket_sndbuf),
NULL },
{ ngx_string("proxy_connect_timeout"),
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
@ -457,6 +473,14 @@ ngx_stream_proxy_handler(ngx_stream_session_t *s)
u->peer.so_keepalive = 1;
}
if (pscf->socket_rcvbuf) {
u->peer.rcvbuf = (int) pscf->socket_rcvbuf;
}
if (pscf->socket_sndbuf) {
u->peer.sndbuf = (int) pscf->socket_sndbuf;
}
u->peer.type = c->type;
u->start_sec = ngx_time();
@ -2381,6 +2405,8 @@ ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf)
conf->proxy_protocol = NGX_CONF_UNSET;
conf->local = NGX_CONF_UNSET_PTR;
conf->socket_keepalive = NGX_CONF_UNSET;
conf->socket_rcvbuf = NGX_CONF_UNSET_SIZE;
conf->socket_sndbuf = NGX_CONF_UNSET_SIZE;
conf->half_close = NGX_CONF_UNSET;
#if (NGX_STREAM_SSL)
@ -2442,6 +2468,10 @@ ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->socket_keepalive,
prev->socket_keepalive, 0);
ngx_conf_merge_size_value(conf->socket_rcvbuf, prev->socket_rcvbuf, 0);
ngx_conf_merge_size_value(conf->socket_sndbuf, prev->socket_sndbuf, 0);
ngx_conf_merge_value(conf->half_close, prev->half_close, 0);
#if (NGX_STREAM_SSL)