Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
src/ | H | 08-Dec-2019 | - | 2,621 | 1,858 | |
t/ | H | 08-Dec-2019 | - | 1,420 | 1,272 | |
.gitignore | H A D | 08-Dec-2019 | 36 | 6 | 5 | |
.project | H A D | 08-Dec-2019 | 213 | 12 | 11 | |
.travis.yml | H A D | 08-Dec-2019 | 61 | 8 | 5 | |
ChangeLog | H A D | 08-Dec-2019 | 1.4 KiB | 66 | 33 | |
LICENSE | H A D | 08-Dec-2019 | 2.7 KiB | 51 | 46 | |
Makefile | H A D | 08-Dec-2019 | 1,023 | 30 | 20 | |
README.md | H A D | 08-Dec-2019 | 7.4 KiB | 307 | 237 | |
build.sh | H A D | 08-Dec-2019 | 11.8 KiB | 513 | 425 | |
config | H A D | 08-Dec-2019 | 972 | 31 | 26 | |
nginx.conf | H A D | 08-Dec-2019 | 1.3 KiB | 82 | 62 | |
tests.sh | H A D | 08-Dec-2019 | 564 | 30 | 21 |
README.md
1# ngx_dynamic_upstream 2 3`ngx_dynamic_upstream` is the module for operating upstreams dynamically with HTTP APIs 4such as [`ngx_http_upstream_conf`](http://nginx.org/en/docs/http/ngx_http_upstream_conf_module.html). 5 6This module also supports stream upstreams manipulation. 7 8Online reconfiguration upstream addresses from DNS by hostname without reloads. 9 10# Build status 11[![Build Status](https://travis-ci.org/ZigzagAK/ngx_dynamic_upstream.svg)](https://travis-ci.org/ZigzagAK/ngx_dynamic_upstream) 12 13# Requirements 14 15`ngx_dynamic_upstream` requires the `zone` directive in the `upstream` context. 16 17# Status 18 19Production ready. 20 21# Directives 22 23## dynamic_upstream 24 25|Syntax |dynamic_upstream| 26|-------|----------------| 27|Default|-| 28|Context|location| 29 30## dynamic_state_file 31 32|Syntax |dynamic_state_file file| 33|-------|----------------| 34|Default|-| 35|Context|upstream| 36 37Persistent state of upstream. 38Example: dynamic_state_file backend.peers; 39 40If you want to add servers in upstream, you **MUST** create backend.peers file manually and add these servers into it. 41Add servers directly into `upstream` section is incorrect and you will see fake 0.0.0.0:1 server in list and backend.peers file. 42 43## dns_update 44 45|Syntax |dns_update 60s [thread pool]| 46|-------|----------------| 47|Default|-| 48|Context|upstream| 49 50Background synchronization hosts addresses by DNS. 51 52## dns_add_down 53 54|Syntax |dns_add_down on/off| 55|-------|----------------| 56|Default|off| 57|Context|upstream| 58 59Add new peers in down state. 60 61## dns_ipv6 62 63|Syntax |dns_ipv6 on| 64|-------|----------------| 65|Default|-| 66|Context|upstream| 67 68Include IPv6 addresses. 69 70# Quick Start 71 72```nginx 73 74http { 75 upstream backends { 76 zone zone_for_backends 1m; 77 server 127.0.0.1:6001; 78 server 127.0.0.1:6002; 79 server 127.0.0.1:6003; 80 } 81 82 # Persistent state 83 # DON't add servers directly into upstream section 84 # Add servers into backend.peers file 85 upstream backends2 { 86 zone zone_for_backends2 1m; 87 dynamic_state_file backend.peers; 88 } 89 90 server { 91 listen 6000; 92 93 location /dynamic { 94 allow 127.0.0.1; 95 deny all; 96 dynamic_upstream; 97 } 98 99 location / { 100 proxy_pass http://backends; 101 } 102 } 103} 104 105stream { 106 upstream backends_stream { 107 zone zone_for_backends_stream 1m; 108 server 127.0.0.1:6001; 109 server 127.0.0.1:6002; 110 server 127.0.0.1:6003; 111 } 112 113 server { 114 listen 6001; 115 proxy_pass backends_stream; 116 } 117} 118``` 119 120## DNS background updates 121 122```nginx 123http { 124 upstream mail { 125 zone mail 1m; 126 dns_update 60s; 127 dns_ipv6 off; 128 server mail.ru; 129 server google.com backup; 130 } 131 132 server { 133 listen 6000; 134 135 location /dynamic { 136 allow 127.0.0.1; 137 deny all; 138 dynamic_upstream; 139 } 140 141 location / { 142 proxy_pass http://backends; 143 } 144 } 145} 146``` 147 148# HTTP APIs 149 150You can operate upstreams dynamically with HTTP APIs. 151 152## list 153 154```bash 155$ curl "http://127.0.0.1:6000/dynamic?upstream=mail" 156server mail.ru addr=217.69.139.201:80; 157server mail.ru addr=94.100.180.201:80; 158server mail.ru addr=217.69.139.200:80; 159server mail.ru addr=94.100.180.200:80; 160server google.com addr=173.194.73.139:80 backup; 161server google.com addr=173.194.73.100:80 backup; 162server google.com addr=173.194.73.101:80 backup; 163server google.com addr=173.194.73.138:80 backup; 164server google.com addr=173.194.73.102:80 backup; 165server google.com addr=173.194.73.113:80 backup; 166$ 167``` 168 169## verbose 170 171```bash 172$ curl "http://127.0.0.1:6000/dynamic?upstream=mail&verbose=" 173server mail.ru addr=94.100.180.200:80 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 174server mail.ru addr=94.100.180.201:80 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 175server mail.ru addr=217.69.139.200:80 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 176server mail.ru addr=217.69.139.201:80 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 177server google.com addr=64.233.165.101:80 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0 backup; 178server google.com addr=64.233.165.102:80 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0 backup; 179server google.com addr=64.233.165.139:80 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0 backup; 180server google.com addr=64.233.165.138:80 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0 backup; 181server google.com addr=64.233.165.100:80 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0 backup; 182server google.com addr=64.233.165.113:80 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0 backup; 183$ 184``` 185 186## update_parameters 187 188```bash 189$ curl "http://127.0.0.1:6000/dynamic?upstream=backends&server=127.0.0.1:6003&weight=10&max_fails=5&fail_timeout=5&max_conns=10" 190server 127.0.0.1:6001 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 191server 127.0.0.1:6002 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 192server 127.0.0.1:6003 weight=10 max_fails=5 fail_timeout=5 max_conns=10 conns=0; 193$ 194``` 195 196The supported parameters are below. 197 198 * weight 199 * max_fails 200 * fail_timeout 201 202## down 203 204```bash 205$ curl "http://127.0.0.1:6000/dynamic?upstream=backends&server=127.0.0.1:6003&down=" 206server 127.0.0.1:6001 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 207server 127.0.0.1:6002 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 208server 127.0.0.1:6003 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0 down; 209$ 210``` 211 212## up 213 214```bash 215$ curl "http://127.0.0.1:6000/dynamic?upstream=backends&server=127.0.0.1:6003&up=" 216server 127.0.0.1:6001 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 217server 127.0.0.1:6002 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 218server 127.0.0.1:6003 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0; 219$ 220``` 221 222## add peer 223 224```bash 225$ curl "http://127.0.0.1:6000/dynamic?upstream=backends&add=&server=127.0.0.1:6004" 226server 127.0.0.1:6001; 227server 127.0.0.1:6002; 228server 127.0.0.1:6003; 229server 127.0.0.1:6004; 230$ 231``` 232 233## add host 234```bash 235$ curl "http://127.0.0.1:6000/dynamic?upstream=backends&add=&server=localhost:6004" 236DNS resolving in progress 237$ 238``` 239Peers will be added in background. 240 241## add backup peer 242 243```bash 244$ curl "http://127.0.0.1:6000/dynamic?upstream=backends&add=&server=127.0.0.1:6004&backup=" 245server 127.0.0.1:6001; 246server 127.0.0.1:6002; 247server 127.0.0.1:6003; 248server 127.0.0.1:6004 backup; 249$ 250``` 251 252## remove peer 253 254```bash 255$ curl "http://127.0.0.1:6000/dynamic?upstream=backends&remove=&server=127.0.0.1:6003" 256server 127.0.0.1:6001; 257server 127.0.0.1:6002; 258server 127.0.0.1:6004; 259$ 260``` 261 262## remove server 263 264```bash 265$ curl "http://127.0.0.1:6000/dynamic?upstream=backends&remove=&server=mail.ru" 266server 127.0.0.1:6001; 267server 127.0.0.1:6002; 268server 127.0.0.1:6004; 269$ 270``` 271 272## add stream 273 274```bash 275$ curl "http://127.0.0.1:6000/dynamic?upstream=backends_stream&add=&server=127.0.0.1:6004&stream=" 276server 127.0.0.1:6001; 277server 127.0.0.1:6002; 278server 127.0.0.1:6003; 279server 127.0.0.1:6004; 280$ 281``` 282 283## add backup stream 284 285```bash 286$ curl "http://127.0.0.1:6000/dynamic?upstream=backends_stream&add=&server=127.0.0.1:6004&backup=&stream=" 287server 127.0.0.1:6001; 288server 127.0.0.1:6002; 289server 127.0.0.1:6003; 290server 127.0.0.1:6004 backup; 291$ 292``` 293 294## remove stream 295 296```bash 297$ curl "http://127.0.0.1:6000/dynamic?upstream=backends_stream&remove=&server=127.0.0.1:6003&stream=" 298server 127.0.0.1:6001; 299server 127.0.0.1:6002; 300server 127.0.0.1:6004; 301$ 302``` 303 304# License 305 306See [LICENSE](https://github.com/cubicdaiya/ngx_dynamic_upstream/blob/master/LICENSE). 307