我已经编写了lua代码并集成在nginx中以将文件上传到s3存储桶中。如果上传失败或签名格式错误,我会收到403 Forbidden,它会发送给客户端以及非常详细的Error XML。 我想截取/返回默认错误消息msg,而不是s3中显示访问密钥ID的详细错误消息。
我尝试在下面添加代码段,但它没有任何影响:
error_page 403 /forbidden;
location = /forbidden {
internal;
content_by_lua_block {
local cjson = require "cjson"
ngx.header.content_type = "application/json; charset=utf-8"
ngx.status = 403
ngx.say(cjson.encode({ status = "Forbidden. Check the Request" }))
return ngx.exit(ngx.status)
}
}
当我看到要上传的curl cmd的响应时,有两个状态代码,100然后是403.
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 403 Forbidden
< Date: Thu, 28 Sep 2017 04:26:31 GMT
< Content-Type: application/xml
< Transfer-Encoding: chunked
< Connection: keep-alive >
如何处理此操作以返回所有403状态代码响应的默认响应。