Express and nginx net :: ERR_CONTENT_LENGTH_MISMATCH

I am developing an Express site that goes through the nginx proxy. Sometimes when I load a page in a browser, I get the following:

GET http://myapp.local/css/bootstrap.css net::ERR_CONTENT_LENGTH_MISMATCH 

enter image description here

If I refresh the page, it usually quits. But if the update is over and over, it will reappear.

What is the problem? What can I do to narrow down the problem here? Here is my nginx conf for this server:

 server { listen 80; server_name www.myapp.local; rewrite ^(.*) http://myapp.local$1 permanent; } server { listen 80; server_name myapp.local; access_log /vagrant/nginx/logs/myapp.local/access.log; error_log /vagrant/nginx/logs/myapp.local/error.log; location / { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } 

This is definitely related to the nginx proxy. Because if I access the site using only the IP address and Node port: http://10.10.10.10:8080 , I never get an error. But if I access it using a proxy host: http://myapp.local , then I will eventually get an error (maybe 1 out of 10 chances I see it).

+6
source share
3 answers

net::ERR_CONTENT_LENGTH_MISMATCH - cache problem. You tell Nginx to bypass the cache if certain conditions are met (in your case, $http_upgrade ).

You should have specified the caching location for nginx in the configuration file somewhere. A quick fix would be to delete the contents of this folder, restart nginx, and then try to access the site again. Another quick fix through caching is to remove the proxy_cache_bypass $http_upgrade;

If you provide more details on setting up caching, perhaps this answer could be improved.

+5
source

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

When buffering is disabled, the response is transmitted to the client synchronously, immediately after receiving it. nginx will not try to read the whole response from the proxy server. The maximum size of data that nginx can receive from the server at a time is specified by the proxy_buffer_size directive.

Thus, you can simply disable proxy buffering to fix this problem:

 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. Therefore, before disabling proxy_buffering check the use of your disk.

+5
source

When I tried the above solution, this did not fix the problem. I also changed the write permission in place, but that didn't work. Then I realized that something was wrong there. In the file storage location, I had something like

"/ storage" + fileName + ".csv"

. I tested the Windows environment and it worked perfectly. But later, when we moved the application to Linux, it stopped working. So later I had to change it to

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

and he began to work normally.

0
source

All Articles