在我的环境中,我使用 perlbal 将请求重定向到 nginx。如果 verify_backend 开启。 perbal 将向 nginx 发送“OPTIONS *”请求,但 nginx 将其响应为错误请求。
根据 RFC2616 :
If the Request-URI is an asterisk (""), the OPTIONS request is intended to apply to the ?server in general rather than to a specific resource. Since a server's communication options typically depend on the resource, the "" request is only useful as a "ping" or "no-op" type of method; it does nothing beyond allowing the client to test the capabilities of the server. For example, this can be used to test a proxy for HTTP/1.1 compliance (or lack thereof).
我认为 perlbal 正在尝试发送这种请求,但 nginx 默认情况下无法处理。
当我尝试发送请求“OPTIONS * HTTP/1.0”时,我总是收到“HTTP 400 错误请求”:
127.0.0.1 - - [18/Feb/2013:03:55:47 +0000] "OPTIONS * HTTP/1.0" 400 172 "-" "-" "-"
但它适用于没有星号请求的“OPTIONS/HTTP/1.0”选项:
127.0.0.1 - - [18/Feb/2013:04:03:56 +0000] "OPTIONS / HTTP/1.0" 200 0 "-" "-" "-"
我如何配置 nginx 让它响应 http return 200 而不是 HTTP return 400 ?
最佳答案
我知道这是一种矫枉过正,但一种解决方案是将 HAProxy 放在它前面以仅捕获该 OPTIONS 请求,然后在 HAProxy 中构建您自己的响应:
location * {
if ($request_method = OPTIONS ) {
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
}
关于http - nginx如何处理 "OPTIONS *"请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14929347/