Nginx修改传入的无效标头

3
我是一名有用的助手,可以为您翻译文本。

我对nginx配置有一个问题。我向nginx发送一个带有无效标头的请求,并希望使用nginx修改该标头使其有效。

请求:

curl -X POST -d "data=string" -H "Host:192.168.99.100" -H "Connection: close" -H "Accept-Encoding: identity" -H "Content-Type: application/x-www-form-urlencoded" -H "Content-Length: 22\r\n" -i http://192.168.99.100/protocol_1.2

注意Content-Length: 22\r\n(CRLF)
然后在error.log中,使用日志级别INFO我会得到
[info] 5#0: *1 client sent invalid "Content-Length" hader while reading client request headers, client: 192.168.99.1, server: example.org,request: "POST /protocol_1.2 HTTP/1.1", host: "192.168.99.100"

很遗憾,我无法修改请求源代码,因此希望在nginx中进行修改。是否有一种方法可以在nginx处理之前修改传入的标头?
我的sites-enabled非常简单:
server {

    listen 80;
    server_name example.org;
    charset utf-8;

    error_log /var/log/nginx/error.log info;

    ignore_invalid_headers on;

    location /static {
        alias /usr/src/app/static;
    }

    location / {
        proxy_pass http://music:8010;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

感谢,Kevin。
2个回答

0

这个论点:

-H "Content-Length: 22\r\n"

应该是:

-H "Content-Length: 22"

-1
也许你可以在nginx.conf中尝试使用'ignore_invalid_headers'选项。供参考。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接