Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 559
Prakash Raman Avatar asked Jul 01 '09 04:07

Prakash Raman


People also ask

How do you fix a URL that is too long?

How To Fix. There are several things that you can do to avoid URLs that are too long: If using dynamic URLs with URL parameters, use server-side URL rewrites to convert them into static, human-readable URLs. Try to minimize the number of parameters in the URL whenever possible.

What is request URI in nginx?

According to NGINX documentation, $request_uri is the original request (for example, /foo/bar. php? arg=baz includes arguments and can't be modified) but $uri refers to the altered URI.

What does the requested URL's length exceeds the capacity limit for this server mean?

This problem might be caused by the Apache limits the set a size of a client's HTTP request-line (e.g. ) and the HTTP request header field size. So you will need to increase the default values if the request URL is this large.


2 Answers

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.

like image 173
Stobor Avatar answered Oct 02 '22 13:10

Stobor


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; 
like image 34
Luke Snowden Avatar answered Oct 02 '22 12:10

Luke Snowden