1

I'm using jQuery to post some form data to my Nginx server but sometimes it fails with a 408 error. When the error happens, apparently the php script to process the posted data is NOT reached at all, as I put some logging function in the first line. And the most weird part is, with the same form data, sometimes the script works, sometimes not. I couldn't figure out why.

Browser: Microsoft Edge 101.0.1210.32

jQuery:1.12.4, code of posting data as below:

$.ajax({
    url: 'save.php',
    dataType: 'json',
    type: 'post',
    contentType: 'application/json',
    data: JSON.stringify( { "comment": comment,"id":id} ),
    processData: false
});

Nginx log:

[03/May/2022:15:11:01 +0700] "POST /save.php HTTP/1.1" 408 0 ...

Nginx conf:

client_max_body_size 10M;
client_body_buffer_size 2048k;
client_header_timeout 60s;
client_body_timeout 60s;
keepalive_timeout 60s;
Dave M
  • 4,494
  • 21
  • 30
  • 30
klemperer
  • 11
  • 1

2 Answers2

0

It is possible to define additional log format - specially for debugging. In nginx.conf in section http

http {
  # ... other config lines

  log_format request_body_log '$remote_addr $remote_user [$time_local] "$request" status:$status bytes_sent:$bytes_sent gzip_ratio:$gzip_ratio connection_requests:$connection_requests request_length:$request_length connection-serial-number:$connection request_time:$request_time "$http_user_agent" "$http_referer" request_body:"$request_body"';

  # ... 
}

To enable it for location:

location / {
  # ...   
  if ($request_method = POST) {
    access_log /var/www/html/logs/nginx_request_body.log request_body_log;
  }
}

This provides in logs a lot of information about every http-request.
P.S. This example for rather old version, maybe Your nginx version has differences.

Sergey Serov
  • 397
  • 3
  • 7
  • 14
0

Solution: We downgraded docker version and now container (MTU 1500) is on host network with default MTU 1496.