一般格式:
location /ip {
default_type text/plain;
return 200 $remote_addr;
}
结果:
$ curl https://example.com/ip
2001:1b48:103::189
json格式:
location /json_ip {
default_type application/json;
return 200 "{\"ip\":\"$remote_addr\"}";
}
返回结果:
$ curl -s https://example.com/json_ip | jq
{
"ip": "2001:1b48:103::189"
}
网友评论