upstream myapp_01 { server 10.102.20.20:80; } upstream myapp_02 { server 10.102.20.211:80; } server { listen 8000; location / { allow 127.0.0.1; deny all; dyups_interface; } } server { listen 80; server_name localhost; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; set $ups myapp; proxy_pass http://$ups; } }
[root@lua conf]# curl http://127.0.0.1:8000/list myapp_01 myapp_02
[root@lua conf]# curl -d "server 10.102.20.20:80 max_fails=3 fail_timeout=5s weight=10 ;server 10.102.20.211 max_fails=3 fail_timeout=5s weight=10;" 127.0.0.1:8000/upstream/myapp success
[root@lua conf]# curl 127.0.0.1:8000/detail myapp_01 server 10.102.20.20:80 weight=1 max_conns=0 max_fails=1 fail_timeout=10 backup=0 down=0 myapp_02 server 10.102.20.211:80 weight=1 max_conns=0 max_fails=1 fail_timeout=10 backup=0 down=0 myapp server 10.102.20.20:80 weight=10 max_conns=0 max_fails=3 fail_timeout=5 backup=0 down=0 server 10.102.20.211:80 weight=10 max_conns=0 max_fails=3 fail_timeout=5 backup=0 down=0
[root@lua conf]# curl -I 10.102.20.103 HTTP/1.1 200 OK Server: nginx/1.14.2 Date: Fri, 13 Dec 2019 01:55:39 GMT Content-Type: text/html; charset=utf-8 Content-Length: 616 Connection: keep-alive Last-Modified: Fri, 14 Dec 2018 09:10:04 GMT ETag: "5c13736c-268" Accept-Ranges: bytes
curl -i -X DELETE 127.0.0.1:8000/upstream/myapp HTTP/1.1 200 OK Server: nginx/1.14.2 Date: Fri, 13 Dec 2019 01:57:43 GMT Content-Length: 7 Connection: keep-alive success
[root@lua conf]# curl http://127.0.0.1:8000/list myapp_01 myapp_02
请求方法 | HTTP接口 | 用途 |
GET | /detail | 获取所有upsteam的清单明细 |
GET | /list | 获取所有upsteam的name |
GET | /upstream/name | 获取指定的upstream内的后端服务器的IP地址和端口 |
POST | /upstream/name | 覆盖指定的upstream的内容,包括IP地址、端口号、权重等信息 |
DELETE | /upstream/name | 删除指定的upstream |
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:动态管理upsteam—nginx_http_dyups_module - Python技术站