Express and nginx net::ERR_CONTENT_LENGTH_MISMATCH Express and nginx net::ERR_CONTENT_LENGTH_MISMATCH express express

Express and nginx net::ERR_CONTENT_LENGTH_MISMATCH


The net::ERR_CONTENT_LENGTH_MISMATCH is a caching issue. You're telling Nginx to bypass the cache if certain conditions are met (in your case $http_upgrade).

You should've specified the caching location for nginx in a configuration file somewhere. A quick fix will be to delete the contents of this folder, restart nginx, and then try accessing the site again. Another quick fix at the expense of caching is to remove the line proxy_cache_bypass $http_upgrade;

If you provide more details on your caching setup, perhaps this answer could be improved.


This is a problem with proxy buffering. When buffering is enabled, nginx receives a response from the proxied server as soon as possible, saving it into the buffers set by the proxy_buffer_size and proxy_buffers directives. If the whole response does not fit into memory, a part of it can be saved to a temporary file on the disk. Writing to temporary files is controlled by the proxy_max_temp_file_size and proxy_temp_file_write_size directives.

When buffering is disabled, the response is passed to a client synchronously, immediately as it is received. nginx will not try to read the whole response from the proxied server. The maximum size of the data that nginx can receive from the server at a time is set by the proxy_buffer_size directive.

So you may simply disable the proxy buffering to fix this issue:

proxy_buffering  off;

Also note that nginx is simply trying to write to a temporary file on the disk and if the disk is full you will get the same error. So before disabling proxy_buffering check your disk usage.


When I tried the aforementioned solution it didn't fix the issue. I also changed the permission to write on the location but it didn't work. Then I realized I did something wrong in there. In the location to store the file, I had something like

"/storage" + fileName + ".csv"

. I was testing on the Windows environment and it was working great. But later when we moved the application to the Linux environment it stopped working. So later I had to change it to

"./storage" + fileName + ".csv"

and it started working normally.