How to set the allowed url length for a nginx request (error code: 414, uri too large)
Asked Answered
S

3

96

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 ?

Shoulders answered 1/7, 2009 at 4:59 Comment(0)
F
141

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.

Fulviah answered 1/7, 2009 at 5:46 Comment(9)
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.Fulviah
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... ;)Detribalize
Thanks @Detribalize - 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...Fulviah
It resolved 414 error but now nginx gives 502 - Bad Gateway error.Gamma
I m not sure what file should have that configuration, does anyone knows?Oceanus
@Oceanus - you probably to understand how NGINX configuration works but the short answer is either nginx.conf or more commonly one of the files included from there.Fulviah
thanks yes I got it on /etc/nginx/nginx.conf thanksOceanus
You also need to increase the buffer-size in uwsgi.ini if you are using uwsgi. #40426657Abyssinia
@SohelPathan Same here, got that fixed by tweaking proxy_buffer_size and proxy_buffers. It still needs those, despite having set proxy_buffering off...Crusado
S
17

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;
Sitnik answered 18/1, 2019 at 16:12 Comment(1)
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.Sitnik
S
6

I had very similar issue but with a different error

upstream sent too big header while reading response header from upstream

In order to fix it I've changed

server {
....
proxy_buffers   4 32k;
proxy_buffer_size   32k;
...
}

For more information you can visit nginx-doc

Shaped answered 23/2, 2022 at 13:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.