我想使用nginx作为某些外部地址ext-address
的模拟,并从本地主机返回特定的json作为POST正文。
我在nginx.conf中做了什么。
location /ext-address {
alias /opt/test/response.json;
}
但似乎,它不会尝试返回 response.json,返回
<html><body><h1>404 Not found</h1></body></html>
您可以使用 error_page
语句返回正常主体。
例如:
location /ext-address {
if ($request_method != POST) { return 404; }
return 405;
error_page 405 =200 /test/response.json;
}
location = /test/response.json {
root /opt;
}
有关详细信息,请参阅此文档。