skip to Main Content

I’m facing an issue with file uploads on my Node.js application hosted behind a Nginx server. The setup involves using the Express-Formidable package as middleware for handling file uploads, which are then sent to an AWS S3 bucket.

The problem is that the file upload request never completes—my API request continues processing until it hits the server timeout, and the file never reaches the S3 bucket. All other API calls work fine, but requests involving file uploads stall indefinitely. After I restart the PM2 process, everything works normally for a while before the issue reoccurs.

When I checked the Nginx error logs, I found the following entry:

Nginx Error Log:

2024/09/04 18:32:44 [error] 63421#63421: *9345 , client: <my_ip>, server: <backend_api>, request: "POST /api/v1/video-project HTTP/2.0", upstream: "http://127.0.0.1:4000/api/v1/video-project", host: "<backend_api>", referrer: "<backend_api>"

Here’s my Nginx config for the server (relevant parts included):

server {

listen 443 ssl http2;

client_max_body_size 600M;

# Proxy settings for the main API

location / {

proxy_pass http://localhost:4000;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection 'upgrade';

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_send_timeout 7200s;

proxy_read_timeout 7200s;

proxy_buffer_size 64k;

proxy_buffers 16 32k;

proxy_busy_buffers_size 64k;

proxy_request_buffering off;

proxy_buffering off;

proxy_connect_timeout 300;

}

}

Questions:

  • Has anyone encountered similar issues with Nginx prematurely closing upstream connections during file uploads? What could be the root cause of this?

  • Could this be a configuration issue with Nginx or something related to the Node.js Express-Formidable package or AWS S3 SDK?

  • Any recommendations on how to debug or resolve this issue? Could this be related to buffer settings or timeout misconfigurations?

Any insights or suggestions would be highly appreciated!

What I’ve Tried:

  • Checked the Nginx error logs but couldn’t find anything beyond the log above.

  • Adjusted the client_max_body_size and proxy settings

2

Answers


  1. Maybe you have a problem with ram memory on the server and your nodejsapplication takes all the RAM, try setting pm2 start app.js --max-memory-restart 500M
    when starting the application .

    Login or Signup to reply.
  2. Please run this command "free -m" on your Server’s Terminal as shown in the image below, It will give you the free space in MBs, and check if you have enough RAM storage on your server. May be your RAM storage is not enough to full fill your request.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search