https://github.com/zigzagak/ngx_http_upsync_upstream
Nginx dynamic upstream synced by http request
https://github.com/zigzagak/ngx_http_upsync_upstream
dynamic-upstream nginx service-discovery upstream
Last synced: 2 months ago
JSON representation
Nginx dynamic upstream synced by http request
- Host: GitHub
- URL: https://github.com/zigzagak/ngx_http_upsync_upstream
- Owner: ZigzagAK
- License: bsd-2-clause
- Created: 2019-01-02T01:04:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-16T18:53:52.000Z (almost 7 years ago)
- Last Synced: 2025-06-30T20:44:12.085Z (12 months ago)
- Topics: dynamic-upstream, nginx, service-discovery, upstream
- Language: C
- Size: 35.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE
Awesome Lists containing this project
README
Name
====
ngx_http_upsync_upstream - Upstream synced by http request.
# Quick Start
## Nginx config
```nginx
http {
healthcheck_buffer_size 128k;
upstream app1 {
zone shm_app1 128k;
upsync localhost:8888/registry/nodes?service=app1;
upsync_header Accept text/plain;
upsync_interval 10s;
upsync_timeout 10s;
upsync_defaults max_conns=10 max_fails=1 fail_timeout=30s;
upsync_file app1.peers;
dns_update 60s;
dns_add_down on;
check passive type=http rise=2 fall=2 timeout=5000 interval=10;
check_request_uri GET /health;
check_response_codes 200;
check_response_body alive;
}
upstream app2 {
zone shm_app2 128k;
upsync localhost:8888/registry/nodes?service=app2;
# Admin:1111
upsync_header Authorization "Basic QWRtaW46MTExMQ==";
upsync_header Accept text/plain;
upsync_interval 10s;
upsync_timeout 10s;
upsync_defaults max_conns=10 max_fails=1 fail_timeout=30s;
upsync_file app2.peers;
dns_update 60s;
dns_add_down on;
check passive type=http rise=2 fall=2 timeout=5000 interval=10;
check_request_uri GET /health;
check_response_codes 200;
check_response_body alive;
}
upstream app3 {
zone shm_app3 128k;
upsync localhost:8888/registry/app3;
# Admin:1111
upsync_header Accept text/plain;
upsync_interval 10s;
upsync_timeout 10s;
upsync_defaults max_conns=10 max_fails=1 fail_timeout=30s;
upsync_file app3.peers;
dns_update 60s;
dns_add_down on;
check passive type=http rise=2 fall=2 timeout=5000 interval=10;
check_request_uri GET /health;
check_response_codes 200;
check_response_body alive;
}
server {
listen 6000;
location /dynamic {
dynamic_upstream;
}
}
server {
# app1
listen 8001;
listen 8002;
listen 8003;
#app2
listen 9001;
listen 9002;
listen 9003;
location = /health {
return 200 'alive';
}
location / {
access_log off;
return 200 'hello';
}
}
server {
listen 10000;
access_log off;
location /app1 {
proxy_pass http://app1;
}
location /app2 {
proxy_pass http://app2;
}
}
server {
listen 8888;
location = /registry/nodes {
if ($arg_service = app1) {
echo "localhost:8001 weight=1 max_conns=10 max_fails=2 fail_timeout=10s";
echo "localhost:8002 weight=2 max_conns=20 max_fails=2 fail_timeout=5s";
echo "localhost:8003 max_conns=50 max_fails=2 fail_timeout=10s backup";
}
if ($arg_service = app2) {
echo "localhost:9001";
echo "localhost:9002";
echo "localhost:9002 backup";
}
}
location = /registry/app3 {
alias conf/app3.txt;
}
location /dynamic {
dynamic_upstream;
}
location /healthcheck/get {
healthcheck_get;
}
location /healthcheck/status {
healthcheck_status;
}
}
}
````