node.jsnginxfile-uploaddigital-oceanhttp-status-code-504

How to resolve Error 504 Gateway Timeout when uploading file in Nodejs App with Nginx proxy


I have a nodejs app deployed on Digital Ocean and running on Ubuntu. I am using Nginx as my reverse proxy to redirect requests to the application's port.

I have been testing this app for quite sometime now and all the past weeks before today, I was able to flawlessly upload files big or small, but just recently the process just started to hang and then return a 504 Gateway timeout. My first instinct is that this has something to do with Nginx, so i did some researcha and most solutions suggested adding the following to a server block in nginx:

client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_max_body_size 100M;

Now i dont think i'll ever allow my users to upload anything above 5MB, but i set the max upload body_size to 100M. But still did not work.

I am at a loss here guys considering this was working just fine days ago and I really avoid messing with Nginx unless in situations like this.

Help me out :)


Solution

  • OK so after further research, I began to look into the possibility that it might be something wrong with my code. So i inspected the project piece by piece and realised that the directory to which I was supposed to uploading files to was not there. I remembered that before my last git commit, I .gitignored it so that i should not be pushing my local uploads along with the rest of the project, so the directory got deleted. Before I was to launch the app in Live Production, I git pulled it into my Digital Ocean ubuntu server, but this time without the uploads directory.

    SO fixing this got my project working perfectly.