我在使用 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.9
或1.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-full
、nginx-light
、nginx-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/