30

I have a large URI and I am trying to configure Nginx to accept it. The URI parameters are 52000 characters in length with a size of 52kb. I have tried accessing the URI without Nginx and it works fine.

But when I use Nginx it gives me an error. --- 414 (Request-URI Too Large)

I have configured the large_client_header_buffers and client_header_buffer_size in the http block but it doesn't seem to be working.

client_header_buffer_size 5120k;
large_client_header_buffers 16 5120k;

Any help will be appreciated.

Thank you.

sushmit sarmah
  • 7,508
  • 6
  • 21
  • 24
  • possible duplicate of [How to set the allowed url length for a nginx request (error code: 414, uri too large)](http://stackoverflow.com/questions/1067334/how-to-set-the-allowed-url-length-for-a-nginx-request-error-code-414-uri-too) – Johanna Larsson May 19 '14 at 07:38
  • Have you considered to use POST-request instead? – Alexey Ten May 19 '14 at 08:05
  • This is not a duplicate of that question. If you go through that question you will see that what is suggested has already been done by me. It still does not work. If I turn off Nginx everything works fine. I wanted to use Nginx for load balancing and I have already done the setup. This is the only roadblock. – sushmit sarmah May 19 '14 at 11:17

2 Answers2

48

I have found the solution. The problem was that there were multiple instances of nginx running. This was causing a conflict and that's why the large_client_header_buffers wasnt working. After killing all nginx instances I restarted nginx with the configuration:

client_header_buffer_size 64k;
large_client_header_buffers 4 64k;

Everything started working after that.

Hope this helps anyone facing this problem.

sushmit sarmah
  • 7,508
  • 6
  • 21
  • 24
0

The problem for me was that there was an earlier server {} block (the default one, actually). By earlier, I mean it comes first when doing nginx -T. Nginx "shouldn't" have matched it, but it did, and nginx was using its configuration, which did not specify any of the directives regarding header length, such as large_client_header_buffers. Why was it used? According to this github comment that's for an add-on nginx headers module:

nginx throws out 414 very early, during reading and parsing the request header's first line. Because it happens so early, no location is matched against the current (guilty) request yet while your more_set_headers directive is a "location configuration" which only takes effect for a request that has already been associated with a location {} block

Solutions:

Do 1 of these 3 things:

  1. Put directives related to request header size in the EARLIER server {} block. It probably needs to go in the earliest one.
  2. Remove the EARLIER server {} block
  3. Delete the EARLIER config file

Example problem configs

#/etc/nginx/conf.d/default.conf

server {
    # Note: even if this block were completely empty, it'd be the same problem!

    listen       80;                                                    
    server_name  localhost;
}
#/etc/nginx/conf.d/mysite

server {
    listen 80;
    server_name mysite.test;

    large_client_header_buffers 4 64k;
}

How to fix

#/etc/nginx/conf.d/default.conf

server {
    # put your request header size directives in here, or remove this file
    client_header_buffer_size 5120k;
    large_client_header_buffers 16 5120k;
}
#/etc/nginx/conf.d/mysite

server {
    listen 80;
    server_name mysite.test;

    # no need for large_client_header_buffers here
}
Tyler Collier
  • 11,489
  • 9
  • 73
  • 80