共计 1161 个字符,预计需要花费 3 分钟才能阅读完成。
依赖
一个内置的 with-http_stub_status_module
模块
配置
启用的时候只须要配置 server
块当中加上一小段拜访 url
即可获取到
location /status {stub_status on;}
docker
实现
目前采纳 nginx:alpine
作为镜像,实现拜访 http://127.0.0.1/status
获取到服务状态信息
因为须要批改 /etc/nginx/conf.d/default.conf
文件,所以咱们能够抉择挂载一个文件或者从新构建一个镜像
上面咱们创立一个 Dockerfile
,该文件次要是在default.conf
文件应用 sed
查找 server_name localhost;
并且在前面退出一段location
FROM nginx:alpine | |
RUN sed -i '/server_name localhost;/a\ location /status {\n stub_status on;\n}' /etc/nginx/conf.d/default.conf |
创立 compose.yaml
文件如下
services: | |
nginx: | |
container_name: demo-nginx | |
image: demo-nginx | |
build: . | |
restart: always | |
ports: | |
- "80:80" |
开始构建镜像
$ docker compose build
启动容器
$ docker compose up -d
查看容器外部 nginx
配置确认 location /status
块存在
$ docker exec demo-nginx cat /etc/nginx/conf.d/default.conf | |
server { | |
listen 80; | |
server_name localhost; | |
location /status {stub_status on;} | |
#access_log /var/log/nginx/host.access.log main; | |
location / { | |
root /usr/share/nginx/html; | |
index index.html index.htm; | |
} | |
.... |
后果验证
浏览器拜访地址 http://127.0.0.1/status
获取返回数据如下
Active connections: 2 | |
server accepts handled requests | |
2 2 4 | |
Reading: 0 Writing: 1 Waiting: 1 |
字段含意
Active connections
: 沉闷连接数-
server
accepts
: 接管申请handled
: 已解决申请requests
: 客户端申请
Reading
: 以后所有连贯中正在读取申请Header
的数量Writing
: 以后所有连贯中正在返回数据的数量Waiting
: 以后期待申请的闲暇客户端连接数
参考浏览
Module ngx_http_stub_status_module
正文完