3

I am having trouble with nginx proxy_pass and PUT without a Content-Length header returning a 411 error.

What I run to test this:

# 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"}

Relevant configuration:

# 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;
    }
}

I found this post which seems to be the same problem:

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

Is there a way to get nginx to proxy PUT requests WITHOUT a Content-Length header?

Does a newer version of nginx NOT suffer from this bug/limitation?

Nick Palmer
  • 2,589
  • 1
  • 25
  • 34
  • 2
    Duplicate http://serverfault.com/questions/164220/is-there-a-way-to-avoid-nginx-411-content-length-required-errors – Danack Mar 21 '13 at 00:18
  • Note that PUT with no body works from curl. Not sure if that is curl adding the zero header or nginx assuming that no header means 0 length. – Nick Palmer Mar 21 '13 at 00:54
  • 1
    "Nginx assuming that no header means zero length" That is what the HTTP spec says http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html "The presence of a message-body in a request is signaled by the inclusion of a Content-Length or Transfer-Encoding header field in the request's message-headers." No length = No body. – Danack Mar 21 '13 at 01:28
  • They have fixed this in more recent versions of nginx apparently but I haven't had time to test it. – Nick Palmer Mar 27 '13 at 22:21

1 Answers1

1

Upgrade to nginx >= 1.4.1 (1.3.9 or 1.4.0 would be enough, but have security issues thx @elhefe - see comments) or install NginxHttpChunkinModule as mentioned here. There are official packages for Debian and RedHat families.

Debian:

  • wheezy backports (currently 1.4.4-1)

    add to /etc/apt/sources.list:

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

    run and install nginx version of your choice (nginx-full, nginx-light, nginx-naxsi)

    apt-get update
    apt-get -t wheezy-backports install nginx-full
    
  • nginx.org package (stable version is currently 1.4.4):

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

    add to /etc/apt/sources.list:

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

    remove current nginx packages:

    apt-get remove nginx-full nginx-common
    

    update packages list:

    apt-get update
    apt-get install nginx
    

    For Debian-like behaviour change update /etc/nginx/nginx.conf

    user  www-data;
    

    and add at the end of http section

    include /etc/nginx/sites-enabled/*;
    
Community
  • 1
  • 1
Tombart
  • 30,520
  • 16
  • 123
  • 136
  • Note that you shouldn't upgrade to nginx 1.3.9 or 1.4.0: http://mailman.nginx.org/pipermail/nginx-announce/2013/000112.html – elhefe Aug 08 '14 at 00:37