找到原因了
ngx.location.capture
这里有个提示
See HTTP method constants methods other than POST. The method option is ngx.HTTP_GET by default.
默认是 GET
方法, 但代理的请求是其他方法, 修正如下
local method_map = {
GET = ngx.HTTP_GET,
HEAD = ngx.HTTP_HEAD,
PUT = ngx.HTTP_PUT,
POST = ngx.HTTP_POST,
DELETE = ngx.HTTP_DELETE,
OPTIONS = ngx.HTTP_OPTIONS,
MKCOL = ngx.HTTP_MKCOL,
COPY = ngx.HTTP_COPY,
MOVE = ngx.HTTP_MOVE,
PROPFIND = ngx.HTTP_PROPFIND,
PROPPATCH = ngx.HTTP_PROPPATCH,
LOCK = ngx.HTTP_LOCK,
UNLOCK = ngx.HTTP_UNLOCK,
PATCH = ngx.HTTP_PATCH,
TRACE = ngx.HTTP_TRACE
}
local method = ngx.req.get_method()
local res =
ngx.location.capture(
"/proxy",
{
method = method_map[method],
share_all_vars = true
}
)