Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore or modify request headers in NGINX

Tags:

nginx

I need to make NGINX ignore / modify a request header.

Problem is some IoT devices are sending a HEAD request with the wrong Content-Length header. That makes NGINX wait for more content and then timeout.

Both dropping the Content-Length header or setting it to 0 should do the trick.

Example

This fails

HEAD / HTTP/1.1
Host: MY_HOST
Content-Length: 59
Content-Type: text/html
Connection: close

This works (Content-Length: 0)

HEAD / HTTP/1.1
Host: MY_HOST
Content-Length: 0
Content-Type: text/html
Connection: close

This works too (no Content-Length)

HEAD / HTTP/1.1
Host: MY_HOST
Content-Type: text/html
Connection: close

How can I make it happen?

like image 909
3v0k4 Avatar asked Nov 07 '22 02:11

3v0k4


1 Answers

I discovered that there's a NGINX module named HeadersMore that allow modifying input headers (and more).

In particular more_clear_input_headers allows to remove input headers and more_set_input_headers allows to modify input headers.

In my case

more_clear_input_headers "Content-Length";

or

more_set_input_headers "Content-Length: 0";
like image 97
3v0k4 Avatar answered Dec 06 '22 11:12

3v0k4