Javascript - ERR_CONTENT_LENGTH_MISMATCH

后端 未结 8 922
广开言路
广开言路 2020-12-02 19:58

I\'m making a basic jquery playground site. I am getting Error: net::ERR_CONTENT_LENGTH_MISMATCH is happening on page load and the background images are not loa

相关标签:
8条回答
  • 2020-12-02 20:20

    Another case where this error showed up for me : When trying to download a file from a node server with Angular 7, I had to redirect with window.location.href = <node_server_url> instead of the usual httpClient.get<any>(<node_server_url>).

    0 讨论(0)
  • 2020-12-02 20:21

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

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

    0 讨论(0)
  • 2020-12-02 20:30

    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
    
    0 讨论(0)
  • 2020-12-02 20:32

    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.

    0 讨论(0)
  • 2020-12-02 20:32

    Here's another way to resolve this issue: http://derekneely.com/2009/06/nginx-failed-13-permission-denied-while-reading-upstream/

    NOTE: From a security point of view, I don't agree with the link where the author suggests to give 777 permissions to the folders. Give the minimum level needed to get the job done (in this case, 700 should be fine, you could even lower, though I did not try that yet).

    0 讨论(0)
  • 2020-12-02 20:33

    I had the same error when building a rails app. I replaced an image with a different image and didn't change the file name, which threw the error above. Simply changing the file name made the problem disappear.

    0 讨论(0)
提交回复
热议问题