http - nginx如何处理 "OPTIONS *"请求?

标签 http nginx bad-request http-options-method

在我的环境中,我使用 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/

相关文章:

java - Tomcat 在处理带有身份验证 header 的 android 请求之前发送 400s

http - 连接将在 Http/2 中保持多长时间

node.js - 使用 nodeJS 的异步 http 调用

java - 我可以强制 jetty *不*包含用于单元测试的 Content-Length header 吗?

ruby-on-rails - nginx 既是反向代理又是 web 服务器

javascript - 从本地主机 :xxxx 加载时的内容安全策略 ( style-src )

node.js - Socket.io SSL 连接与 Nginx 和 Express

api - jira REST API 创建问题,包括组件

Tomcat 服务器响应此 URL 的 400 错误请求

java - 如何使用 session ID 使 http session 无效