公众号关注 「奇妙的 Linux 世界」
设为「星标」,每天带你玩转 Linux !
经常遇到一些监听地址不是 IP:Port
而是 Unix Socket
的程序,这些程序如果使用的是 HTTP
协议,Unix Socket
接口也可以用 curl
访问的。
例如 ingress-nginx
的监听地址为 unix:/tmp/nginx-status-server.sock
。
server {
listen unix:/tmp/nginx-status-server.sock;
set $proxy_upstream_name "internal";
keepalive_timeout 0;
gzip off;
access_log off;
location /healthz {
return 200;
}
location /nginx_status {
stub_status on;
}
... 省略...
}
用 curl
访问它的 Unix Socket
的方法如下:
$ curl --unix-socket /tmp/nginx-status-server.sock http://localhost/nginx_status
Active connections: 77
server accepts handled requests
64273 64273 971368
Reading: 0 Writing: 12 Waiting: 65
这里 --unix-socket
参数是用来指定 Unix Socket 文件的地址, http://localhost/nginx_status
为要请求的路径。
注意: localhost 可以根据实际情况更改成其它值但不可省略,如果省略后请求就变成
http://nginx_status
,那么nginx_status
会被认作是Host
,Path
被认为是/
$ curl -v --unix-socket /tmp/nginx-status-server.sock http://nginx_status
* Expire in 0 ms for 6 (transfer 0xe464ab3dd0)
* Trying /tmp/nginx-status-server.sock...
* Expire in 200 ms for 4 (transfer 0xe464ab3dd0)
* Connected to nginx_status (/tmp/nginx-status-server.sock) port 80 (#0)
> GET / HTTP/1.1
> Host: nginx_status
> User-Agent: curl/7.64.0
> Accept: */*
本文转载自:「小鸟技术笔记」,原文:https://tinyurl.com/y6p32tk3,版权归原作者所有。欢迎投稿,投稿邮箱: editor@hi-linux.com。
你可能还喜欢
点击下方图片即可阅读
一文搞懂 Redis 的三种集群方案
点击上方图片,打开小程序,加入「玩转 Linux」圈子
更多有趣的互联网新鲜事,关注「奇妙的互联网」视频号全了解!