Javascript - ERR_CONTENT_LENGTH_MISMATCH

If you are using nginx + proxied server, try: proxy_buffering off;

More infos: https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/


Summary

Here is a more detailed explanation of what happened in my case. The selected answer here helped me solve my problem and this is basically a more detailed version of the selected answer on hows and whys!

Explaining Nginx Permissions

You can run nginx as a nobody user and that is the common practice in most sample configs. You will find this line at the top of your config:

user nobody;

It is however suggested that for your web-apps static contents, such as css, js, and image files to allow nginx access and cash it through bypassing your web-app
container. This the part of your config where it reads:

location ^~ /static {
    alias /path/to/your/static/folder/;
    autoindex on;
    expires max;    
}

This is the folder nginx needs to have access to.

On the other hand, there is nginx dedicated folder where in the above answer's case was in:

/usr/local/var/run/nginx/

In my case (CentOS) it was in:

/var/lib/nginx/

How can things go wrong?

In either of these cases you can break nginx:

1- Nginx runs as nobody but doesn't have the right access to your static folder.

2- Nginx runs as nobody but then runs as root to gain access to your static folder.

Solution

Best solution in my case was to change the permission of the nginx dedicated folder to match with my static folder. And then run nginx with as a user with the right access to both.


I am getting Error: net::ERR_CONTENT_LENGTH_MISMATCH

Have a look at your server logs to determine what the real issue is.

For me the problem lay somewhere between nginx and file permissions:

  • tail -f /usr/local/var/log/nginx/error.log or run nginx -t to determine your conf location, where you could specify a custom log path.
  • refresh the asset in your browser, eg http://localhost:3000/assets/jquery/jquery.js

You may see something like this in the logs:

"/usr/local/var/run/nginx/proxy_temp/9/04/0000000049" failed (13: Permission denied) while reading upstream for file xyz

Heres how I fixed:

sudo nginx -s stop    
sudo rm -rf /usr/local/var/run/nginx/*    
sudo nginx