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

时间:2013-03-20 22:17:04

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

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

我跑来测试这个:

# 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代理PUT请求而不使用Content-Length标头?

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

1 个答案:

答案 0 :(得分:1)

升级到nginx >= 1.4.11.3.91.4.0就足够了,但是出现安全问题@elhefe - 请参阅评论)或按照NginxHttpChunkinModule安装here }。 Debian和RedHat家族有official packages

<强>的Debian

  • wheezy backports(目前为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/*;