diff --git a/kong.conf.default b/kong.conf.default index ca742928bb9..2003261d680 100644 --- a/kong.conf.default +++ b/kong.conf.default @@ -185,6 +185,27 @@ # `text/html`, `application/json`, and # `application/xml`. +#client_max_body_size = 0 # Defines the maximum request body size allowed + # by Kong, specified in the Content-Length + # request header. If a request exceeds this + # limit, Kong will respond with a 413 (Request + # Entity Too Large). Setting this value to 0 + # disables checking of request body size. + +#client_body_buffer_size = 8k # Defines the buffer size for reading the + # request body. If the client request body is + # larger than this value, the body will be + # buffered to disk. Note that when the body is + # buffered to disk Kong plugins that access or + # manipulate the request body may not work, so + # it is advisable to set this value as high as + # possible (e.g., set it as high as + # `client_max_body_size` to force request + # bodies to be kept in memory). Do note that + # high-concurrency environments will require + # significant memory allocations to process + # many concurrent large request bodies. + #------------------------------------------------------------------------------ # DATASTORE #------------------------------------------------------------------------------ diff --git a/kong/conf_loader.lua b/kong/conf_loader.lua index dfc71191d2e..fecb7bbcb5c 100644 --- a/kong/conf_loader.lua +++ b/kong/conf_loader.lua @@ -70,6 +70,7 @@ local CONF_INFERENCES = { latency_tokens = {typ = "boolean"}, error_default_type = {enum = {"application/json", "application/xml", "text/html", "text/plain"}}, + client_max_body_size = {typ = "string"}, database = {enum = {"postgres", "cassandra"}}, pg_port = {typ = "number"}, diff --git a/kong/templates/kong_defaults.lua b/kong/templates/kong_defaults.lua index 63b38164dec..e38b47540cb 100644 --- a/kong/templates/kong_defaults.lua +++ b/kong/templates/kong_defaults.lua @@ -31,6 +31,8 @@ upstream_keepalive = 60 server_tokens = on latency_tokens = on error_default_type = text/plain +client_max_body_size = 0 +client_body_buffer_size = 8k database = postgres pg_host = 127.0.0.1 diff --git a/kong/templates/nginx_kong.lua b/kong/templates/nginx_kong.lua index 3c0385952cc..3c3779662c9 100644 --- a/kong/templates/nginx_kong.lua +++ b/kong/templates/nginx_kong.lua @@ -19,7 +19,7 @@ error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}}; >-- reset_timedout_connection on; # disabled until benchmarked > end -client_max_body_size 0; +client_max_body_size ${{CLIENT_MAX_BODY_SIZE}}; proxy_ssl_server_name on; underscores_in_headers on; @@ -84,6 +84,7 @@ server { access_log ${{PROXY_ACCESS_LOG}}; error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}}; + client_body_buffer_size ${{CLIENT_BODY_BUFFER_SIZE}}; > if ssl then listen ${{PROXY_LISTEN_SSL}} ssl;