Skip to content

Added max_conns for nginx >= 1.11.5 #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Defines a server for an upstream. The module adds the ability to specify a `reso
The following parameters can be used (see nginx's [server documentation](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server) for details):

`weight=number`
`max_conns=number`
`max_fails=number`
`fail_timeout=time`
`backup`
Expand All @@ -52,7 +53,7 @@ The following parameters can be used (see nginx's [server documentation](http://

# Compatibility

Tested with nginx 1.6, 1.7, 1.8, 1.9.
Tested with nginx 1.6, 1.7, 1.8, 1.9, 1.11.

## Alternatives

Expand Down
24 changes: 24 additions & 0 deletions ngx_http_upstream_dynamic_servers.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ static char * ngx_http_upstream_dynamic_server_directive(ngx_conf_t *cf, ngx_com
time_t fail_timeout;
ngx_str_t *value, s;
ngx_url_t u;
#if nginx_version >= 1011005
ngx_int_t weight, max_conns, max_fails;
#else
ngx_int_t weight, max_fails;
#endif
ngx_uint_t i;
ngx_http_upstream_server_t *us;

Expand All @@ -117,6 +121,9 @@ static char * ngx_http_upstream_dynamic_server_directive(ngx_conf_t *cf, ngx_com
value = cf->args->elts;

weight = 1;
#if nginx_version >= 1011005
max_conns = 0;
#endif
max_fails = 1;
fail_timeout = 10;

Expand All @@ -137,6 +144,23 @@ static char * ngx_http_upstream_dynamic_server_directive(ngx_conf_t *cf, ngx_com
continue;
}

#if nginx_version >= 1011005
if (ngx_strncmp(value[i].data, "max_conns=", 10) == 0) {

if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_CONNS)) {
goto not_supported;
}

max_conns = ngx_atoi(&value[i].data[10], value[i].len - 10);

if (max_conns == NGX_ERROR) {
goto invalid;
}

continue;
}
#endif

if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) {

if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) {
Expand Down