77

I am using Nginx in front of 10 mongrels.

When I make a request with size larger then 2900 I get back an:

error code 414: uri too large

Does anyone know the setting in the nginx configuration file which determines the allowed uri length ?

Roald Nefs
  • 886
  • 8
  • 20
Prakash Raman
  • 11,331
  • 26
  • 71
  • 124

2 Answers2

111

From: http://nginx.org/r/large_client_header_buffers

Syntax: large_client_header_buffers number size ;
Default: large_client_header_buffers 4 8k;
Context: http, server

Sets the maximum number and size of buffers used for reading large client request header. A request line cannot exceed the size of one buffer, or the 414 (Request-URI Too Large) error is returned to the client. A request header field cannot exceed the size of one buffer as well, or the 400 (Bad Request) error is returned to the client. Buffers are allocated only on demand. By default, the buffer size is equal to 8K bytes. If after the end of request processing a connection is transitioned into the keep-alive state, these buffers are released.

so you need to change the size parameter at the end of that line to something bigger for your needs.

Community
  • 1
  • 1
Stobor
  • 40,013
  • 6
  • 62
  • 64
  • 2
    Thanks @VBart - back when I answered this the wiki was the only docs, so I didn't realise they had added an "official" documentation section. – Stobor Feb 25 '14 at 06:17
  • hi you should add ; to the end of the syntax large_client_header_buffers 4 4k/8k; there are some lazy copy pasters like me that you can save their time by adding it... ;) – talsibony Nov 28 '16 at 16:26
  • 1
    Thanks @talsibony - that was a direct copy/paste from the documentation over 7 years ago, it looks like they've updated it since then. I'll update it here... – Stobor Dec 16 '16 at 01:45
  • 3
    It resolved 414 error but now nginx gives 502 - Bad Gateway error. – Sohel Pathan Dec 27 '19 at 12:41
  • I m not sure what file should have that configuration, does anyone knows? – Guido Sep 15 '20 at 21:08
  • @Guido - you probably to understand [how NGINX configuration works](https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/) but the short answer is either `nginx.conf` or more commonly one of the files included from there. – Stobor Sep 15 '20 at 22:46
  • thanks yes I got it on /etc/nginx/nginx.conf thanks – Guido Sep 15 '20 at 22:56
  • You also need to increase the buffer-size in uwsgi.ini if you are using uwsgi. https://stackoverflow.com/questions/40426157/nginx-url-limit-502-gateway – user2608613 Nov 06 '20 at 17:42
  • @SohelPathan Same here, got that fixed by tweaking `proxy_buffer_size` and `proxy_buffers`. It still needs those, despite having set `proxy_buffering off`... – Luc Dec 06 '20 at 18:55
13

For anyone having issues with this on https://forge.laravel.com, I managed to get this to work using a compilation of SO answers;

You will need the sudo password.

sudo nano /etc/nginx/conf.d/uploads.conf

Replace contents with the following;

fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

client_max_body_size 24M;
client_body_buffer_size 128k;

client_header_buffer_size 5120k;
large_client_header_buffers 16 5120k;
Luke Snowden
  • 3,413
  • 2
  • 31
  • 61
  • This file no longer seems to exist when creating new servers via forge which means you can add it straight into the server block via the forge admin panel. – Luke Snowden Sep 24 '19 at 10:29