没有 Content-Length header 的 PUT 的 nginx proxy_pass 返回 411

标签 nginx reverse-proxy http-status-code-411

我在使用 nginx proxy_pass 和 PUT 时遇到问题,没有返回 411 错误的 Content-Length header 。

我运行什么来测试这个:

# curl -XPUT http://localhost:8080/
<html>
<head><title>411 Length Required</title></head>
<body bgcolor="white">
<center><h1>411 Length Required</h1></center>
<hr><center>nginx/1.1.19</center>
</body>
</html>
# touch temp
# curl -X PUT http://localhost:8080/ -T temp
{"response": "ok"}

相关配置:

# Proxy to Backend Server
server {
    listen localhost:8080;

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://backend_server;
    }
}

我发现这个帖子似乎是同样的问题:

http://forum.nginx.org/read.php?2,72279,72279#msg-72279

有没有办法让 nginx 代理没有 Content-Length header 的 PUT 请求?

较新版本的 nginx 是否不受此错误/限制的影响?

最佳答案

升级到nginx >= 1.4.1(1.3.91.4.0就够了,但是有安全问题thx @ elhefe - 查看评论)或安装 NginxHttpChunkinModule如前所述here .有official packages适用于 Debian 和 RedHat 系列。

Debian:

  • wheezy 向后移植(目前为 1.4.4-1)

    添加到/etc/apt/sources.list:

    deb http://ftp.debian.org/debian/ wheezy-backports main
    

    运行并安装您选择的 nginx 版本(nginx-fullnginx-lightnginx-naxsi)

    apt-get update
    apt-get -t wheezy-backports install nginx-full
    
  • nginx.org包(稳定版目前是1.4.4):

    wget http://nginx.org/keys/nginx_signing.key
    apt-key add nginx_signing.key
    

    添加到/etc/apt/sources.list:

    deb http://nginx.org/packages/debian/ wheezy nginx
    deb-src http://nginx.org/packages/debian/ wheezy nginx
    

    删除当前的 nginx 包:

    apt-get remove nginx-full nginx-common
    

    更新包列表:

    apt-get update
    apt-get install nginx
    

    对于类似 Debian 的行为更改更新 /etc/nginx/nginx.conf

    user  www-data;
    

    并在http部分的末尾添加

    include /etc/nginx/sites-enabled/*;
    

关于没有 Content-Length header 的 PUT 的 nginx proxy_pass 返回 411,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15535854/

相关文章:

google-chrome - Chrome 基本身份验证自定义消息停止工作

c++ - 错误 411 需要长度 c++,libcurl PUT 请求

php - 来自用户而不是 Nginx 反向代理服务器的 REMOTE_ADDR IP

laravel - 通过 Nginx 将 2 个域链接到 1 个 Laravel 项目

nginx 反向代理到一组基于 http 引用的 URL 中带有附加路径的页面?

authentication - 使用 AWS CloudFront 时,如何向公众隐藏自定义源服务器?

ssl - 用于在 HTTPS 前端请求 HTTP 后端的 Nginx 反向代理

java - Android DefaultHttpClient POST 方法无法设置内容长度,获取 Http 错误 411

redirect - 如何处理nginx反向代理https到http方案重定向