位置proxy_pass POST在斜杠重定向后给出GET

时间:2018-12-31 16:20:13

标签: http nginx microservices

我有这个规则

location /report/ {
  rewrite ^(.*[^/])$ $1/ permanent;
  proxy_pass http://wsReport/;
}

通过邮递员打电话时,我会有不同的行为。

呼叫:获取/报告/->好的,正确!代码:200个json结果

呼叫:POST /报告/->好的,正确!代码:405

呼叫:获取/报告->好的,正确!代码:200个json结果

CALL:POST / report->错误(行为不正确)代码:200 json结果(与get的结果相同)

如果我查看nginx日志,我会遇到这种情况:

对于GET:

nginx           | [31/Dec/2018:16:14:22 +0000] DOMAIN :: 2.44.210.5 - -  "GET /report HTTP/1.1" 301 178 "-" "PostmanRuntime/7.1.1" "-"
report          | Executing (default): SELECT "id", "text", "message", "valid_from", "valid_to", "creation_date" AS "createdAt", "edit_date" AS "updatedAt" FROM "truebox_api_survey" AS "Survey";
report          | {"level":"\u001b[32minfo\u001b[39m","message":"HTTP GET /","meta":{"res":{"statusCode":200},"req":{"url":"/","headers":{"host":"DOMAIN","connection":"close","authorization":"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InBhc2FsaW5vIiwiZXhwIjoxNTQ4ODQ2MjcyLCJlbWFpbCI6InBhc2FsaW5vQGdtYWlsLmNvbSIsIm9yaWdfaWF0IjoxNTQ2MjU0MjcyfQ.MVTLUCAk9QMlyqqr09NHgk03pVRrGLj6wY5tb3S4hoA","cache-control":"no-cache","postman-token":"5d9250e5-1aad-4391-9dc9-783c0baf7718","user-agent":"PostmanRuntime/7.1.1","accept":"*/*","accept-encoding":"gzip, deflate","referer":"https://DOMAIN/report"},"method":"GET","httpVersion":"1.0","originalUrl":"/","query":{}},"responseTime":66}}
nginx           | [31/Dec/2018:16:14:22 +0000] DOMAIN :: 2.44.210.5 - -  "GET /report/ HTTP/1.1" 200 484 "https://DOMAIN/report" "PostmanRuntime/7.1.1" "-"

对于POST:

nginx           | [31/Dec/2018:16:16:33 +0000] DOMAIN :: 2.44.210.5 - -  "POST /report HTTP/1.1" 301 178 "-" "PostmanRuntime/7.1.1" "-"
report          | Executing (default): SELECT "id", "text", "message", "valid_from", "valid_to", "creation_date" AS "createdAt", "edit_date" AS "updatedAt" FROM "truebox_api_survey" AS "Survey";
report          | {"level":"\u001b[32minfo\u001b[39m","message":"HTTP GET /","meta":{"res":{"statusCode":200},"req":{"url":"/","headers":{"host":"DOMAIN","connection":"close","authorization":"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InBhc2FsaW5vIiwiZXhwIjoxNTQ4ODQ2MjcyLCJlbWFpbCI6InBhc2FsaW5vQGdtYWlsLmNvbSIsIm9yaWdfaWF0IjoxNTQ2MjU0MjcyfQ.MVTLUCAk9QMlyqqr09NHgk03pVRrGLj6wY5tb3S4hoA","cache-control":"no-cache","postman-token":"b6f633a2-0dd4-4746-9be1-73a1ff4f608a","user-agent":"PostmanRuntime/7.1.1","accept":"*/*","accept-encoding":"gzip, deflate","referer":"https://DOMAIN/report"},"method":"GET","httpVersion":"1.0","originalUrl":"/","query":{}},"responseTime":86}}
nginx           | [31/Dec/2018:16:16:33 +0000] DOMAIN :: 2.44.210.5 - -  "GET /report/ HTTP/1.1" 200 484 "https://DOMAIN/report" "PostmanRuntime/7.1.1" "-"

我不希望重定向到GET,但POST必须以相同的方式返回405错误(如果有斜杠)。

0 个答案:

没有答案