Unit: Problem with body size

Created on 19 Jun 2018  Â·  4Comments  Â·  Source: nginx/unit

Hello
I have some problem with body request size in unit 1.2
If request body specified in header Content-Length is greater than 2Mb, proxy server responding HTTP code 413 Payload Too Large

For example, request headers:

Content-Length: 2979050
:method: POST
:scheme: https
Content-Type: application/json; charset=UTF-8
Accept: application/json
Connection: keep-alive
Accept-Language: en-us
Accept-Encoding: br, gzip, deflate

In log Nginx

…
2018/06/19 08:07:32 [debug] 43#43: *6595 http init upstream, client timer: 1
2018/06/19 08:07:32 [debug] 43#43: *6595 posix_memalign: 000055AD7436EC00:4096 @16
2018/06/19 08:07:32 [debug] 43#43: *6595 http script copy: "Host"
2018/06/19 08:07:32 [debug] 43#43: *6595 http script var: “domain.com"
2018/06/19 08:07:32 [debug] 43#43: *6595 http script copy: "X-Real-IP"
2018/06/19 08:07:32 [debug] 43#43: *6595 http script var: “XXX.XXX.XXX.XXX”
2018/06/19 08:07:32 [debug] 43#43: *6595 http script copy: "X-Forwarded-For"
2018/06/19 08:07:32 [debug] 43#43: *6595 http script var: "XXX.XXX.XXX.XXX"
2018/06/19 08:07:32 [debug] 43#43: *6595 http script copy: "X-Forwarded-Host"
2018/06/19 08:07:32 [debug] 43#43: *6595 http script var: “domain.com”
2018/06/19 08:07:32 [debug] 43#43: *6595 http script copy: "Connection"
2018/06/19 08:07:32 [debug] 43#43: *6595 http script copy: "close"
2018/06/19 08:07:32 [debug] 43#43: *6595 http script copy: "Content-Length"
2018/06/19 08:07:32 [debug] 43#43: *6595 http script var: "2979051"
2018/06/19 08:07:32 [debug] 43#43: *6595 http script copy: ""
2018/06/19 08:07:32 [debug] 43#43: *6595 http proxy header: "content-type: application/json; charset=UTF-8"
2018/06/19 08:07:32 [debug] 43#43: *6595 http proxy header: "accept: application/json"
…
2018/06/19 08:07:32 [debug] 43#43: *6595 http upstream request: "xxxxxxxxxxxxxx"
2018/06/19 08:07:32 [debug] 43#43: *6595 http upstream send request handler
2018/06/19 08:07:32 [debug] 43#43: *6595 http upstream send request
2018/06/19 08:07:32 [debug] 43#43: *6595 http upstream send request body
2018/06/19 08:07:32 [debug] 43#43: *6595 tcp_nodelay
2018/06/19 08:07:32 [debug] 43#43: *6595 chain writer buf fl:1 s:1595
2018/06/19 08:07:32 [debug] 43#43: *6595 chain writer in: 000055AD7436F2A0
2018/06/19 08:07:32 [debug] 43#43: *6595 writev: 1595 of 1595
2018/06/19 08:07:32 [debug] 43#43: *6595 chain writer out: 0000000000000000
2018/06/19 08:07:32 [debug] 43#43: *6595 event timer del: 24: 4470147577
2018/06/19 08:07:32 [debug] 43#43: *6595 http upstream request: “xxxxxxxxxxxxxx”
2018/06/19 08:07:32 [debug] 43#43: *6595 http upstream process header
2018/06/19 08:07:32 [debug] 43#43: *6595 malloc: 000055AD74329D00:4096
2018/06/19 08:07:32 [debug] 43#43: *6595 recv: eof:0, avail:1
2018/06/19 08:07:32 [debug] 43#43: *6595 recv: fd:24 219 of 4096
2018/06/19 08:07:32 [debug] 43#43: *6595 http proxy status 413 "413 Payload Too Large"
2018/06/19 08:07:32 [debug] 43#43: *6595 http proxy header: "Content-Type: text/html"
2018/06/19 08:07:32 [debug] 43#43: *6595 http proxy header: "Server: Unit/1.2"
2018/06/19 08:07:32 [debug] 43#43: *6595 http proxy header: "Date: Tue, 19 Jun 2018 08:07:32 GMT"
2018/06/19 08:07:32 [debug] 43#43: *6595 http proxy header: "Content-Length: 66"
2018/06/19 08:07:32 [debug] 43#43: *6595 http proxy header: "Connection: close"
2018/06/19 08:07:32 [debug] 43#43: *6595 http proxy header done
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 header filter
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 push resources
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 output header: ":status: 413"
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 output header: "server: nginx"
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 output header: "date: Tue, 19 Jun 2018 08:20:49 GMT"
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 output header: "content-type: text/html"
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 output header: "content-length: 66"
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 output header: "x-frame-options: SAMEORIGIN"
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 output header: "x-xss-protection: 1; mode=block"
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 output header: "x-content-type-options: nosniff"
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 output header: "referrer-policy: no-referrer-when-downgrade"
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 output header: "strict-transport-security: max-age=31536000; includeSubDomains; preload"
2018/06/19 08:07:32 [debug] 43#43: *6595 http2:31 create HEADERS frame 000055AD7436F6E0: len:205 fin:0
2018/06/19 08:07:32 [debug] 43#43: *6595 http cleanup add: 000055AD7436F7C8
2018/06/19 08:07:32 [debug] 43#43: *6595 http2 frame out: 000055AD7436F6E0 sid:31 bl:1 len:205
2018/06/19 08:07:32 [debug] 43#43: *6595 malloc: 000055AD7467C380:16384

Nginx configuration parameters set

http {
…
client_max_body_size 128M;
client_body_buffer_size  16k;
client_header_buffer_size 8k;
client_max_body_size 128M;
large_client_header_buffers 2 8k;
client_body_timeout   12;
client_header_timeout 12;
keepalive_timeout   10 60;
send_timeout           5;
reset_timedout_connection on;
…
}

Unit application config

{
  "listeners": {
    "*:9000": {
      "application": "api"
    }
  },

  "applications": {
    "api": {
      "type": "php",
      "user": "www-data",
      "group": "www-data",
      "options": {
          "file": "/etc/php7/php.ini",
          "admin": {
              "memory_limit": "128M",
              "post_max_size": "128M",
              "upload_max_filesize": "128M"
          },
          "user": {
              "display_errors": "0"
          }
      },
      "processes":  {
        "max": 20,
        "spare": 0
      },
      "root": “/www/path”,
      "index": "index.php",
      "script": "index.php"
    }
  }
}

PHP configuration parameters set

$ cat /etc/php7/php.ini |grep 128
; Maximum amount of memory a script may consume (128MB)
memory_limit = 128M
post_max_size = 128M
upload_max_filesize = 128M
;   0  (MD5 128 bits)

Unit debug log in attachment

unit.log

bug

All 4 comments

Hi,
What about this issue?
How can I resolve my problem, because I use Unit in production

There should be a setting. Currently the only way to increase the limit is changing a constant in sources, e.g. to 128 Mb:

diff -r 32c82b4c2df6 src/nxt_router.c
--- a/src/nxt_router.c  Fri Jun 22 20:42:31 2018 +0300
+++ b/src/nxt_router.c  Mon Jun 25 16:11:56 2018 +0300
@@ -1521,7 +1521,7 @@ nxt_router_conf_create(nxt_task_t *task,
         skcf->large_header_buffer_size = 8192;
         skcf->large_header_buffers = 4;
         skcf->body_buffer_size = 16 * 1024;
-        skcf->max_body_size = 2 * 1024 * 1024;
+        skcf->max_body_size = 128 * 1024 * 1024;
         skcf->idle_timeout = 65000;
         skcf->header_read_timeout = 5000;
         skcf->body_read_timeout = 5000;

@VBart many thanks - it works for me :)

Now it's configurable via control API. The relevant interface was added with commit https://github.com/nginx/unit/commit/1abdcfb2d85a04b27ac4fc52619b63917b980839 and will be a part of following Unit 1.3 release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lolgab picture lolgab  Â·  3Comments

yujinqiu picture yujinqiu  Â·  5Comments

krombel picture krombel  Â·  3Comments

Izorkin picture Izorkin  Â·  4Comments

hongzhidao picture hongzhidao  Â·  3Comments