I have a node server running on nginx as a reverse proxy, which is supposed to handle image uploads. Its ssl cert and domain are configured through cloudflare.
Aside from setting the proxy_pass to pass 443 requests to the node on localhost, I haven't changed the default configuration much. The more notable nginx directives I have set at the bottom of the http block are:
# Disabled nginx testing for overweight requests - handled in node
client_max_body_size 0;
# Request and response buffering disabled - to try and be able to reject overweight requests in node ASAP
proxy_request_buffering off;
proxy_buffering off;
# Enabled to avoid buffering http 1.1 chunked if sent
proxy_http_version 1.1;
# Disabled writing responses to a file
proxy_max_temp_file_size 0;
Regardless of the client used - postman/insomnia/axios - when sending form data requests with a 4MB image as one of the properties through http, the request reaches the first node middleware after approximately 100ms, which is great.However, when sending the same request over https, it takes approximately 4 seconds to reach that first node middleware. 4 seconds being approximately the time needed to send over the entirety of the request (file).
When sending GET requests to a simple endpoint returning a 200 OK response, http and https calls take a similar amount of time to resolve - within 100ms from each other- with http being slightly faster.That leads me to believe that the huge overhead observed when sending form data requests is caused by the https request not being passed to the node server immediately as it's being received by nginx.
When I enable nginx client_max_body_size directive and set it to i.e. 256K. The same problem arises - http call is rejected with a 413 response from nginx after a reasonable ~100ms, while https request takes around 4 seconds until 413 rejection.
I have tested a bunch of different directive configurations but nothing affected https upload speed in a significant manner. At this point I'm running out of ideas and would appreciate any pointers as to what can cause that and what the solution would be. Cheers!