nginx-openresty通过location调用显示upstream信息
背景
有时候查看nginx的upstream配置得知配置后端的ip地址和端口,但从日志里面发现提示后端不存在,想知道nginx的内存里面是否存在upstream的加载信息,判断后端是否真正的存活
示例
nginx版本: openresty
# /usr/local/openresty/nginx/sbin/nginx -v
nginx version: openresty/1.15.8.3
关键配置信息
location = /upstream_show {
set $upstream_svc "show-upstreams";
upstream_show;
}
具体配置-在server字段引进
server {
set $upstream_svc "-";
listen 80;
server_name bp-inner-gateway-dev.2haohr.com;
access_log /var/log/nginx/bp-inner-gateway-dev.2haohr.com-access.log main;
error_log /var/log/nginx/bp-inner-gateway-dev.2haohr.com-error.log;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_read_timeout 3600;
proxy_connect_timeout 1;
proxy_buffering off;
location = /upstream_show {
set $upstream_svc "show-upstreams";
upstream_show;
}
include /etc/nginx/conf.d/bp-inner-gateway-dev.2haohr.com/*.conf;
}
效果
# curl http://bp-inner-gateway-dev.2haohr.com/upstream_show
Upstream name: eebo.ehr.salesclue; Backend server count: 1
server 10.21.0.11:15390 weight=1 max_fails=2 fail_timeout=10s;
Upstream name: eebo.ehr.metric_performance; Backend server count: 1
server 10.21.0.10:9191 weight=1 max_fails=2 fail_timeout=10s;
Upstream name: eebo.ehr.salescenter; Backend server count: 1
server 10.21.0.11:15250 weight=1 max_fails=2 fail_timeout=10s;
Upstream name: ehr-order_center; Backend server count: 1
server 10.21.0.11:48010 weight=1 max_fails=2 fail_timeout=10s;