美文网首页
Step over nginx buffer issue

Step over nginx buffer issue

作者: 不吃猫的鱼_zjh | 来源:发表于2018-07-02 23:28 被阅读0次

    Background

    I have been using nginx as reverse proxy for my daily development work. After upgrading nginx today, it somehow stops working correctly: a vendor.js file built from webpack has not been served properly. I get the following error from chrome console:

    GET http://nginx.example.com/dist/js/vendor.js net::ERR_CONTENT_LENGTH_MISMATCH 
    

    I take some quick lookarounds and find out:

    • Network tab shows the vendor.js request has a status code 200.
      • The response header seems to be fine. However, there is nothing to preview in chrome network tab.

      • The Content-Length of the vendor.js matches the real size of the file.

        # ls -l : get the size in byte
        -rw-r--r--   1 michaelzheng  staff   4844863 Jul  2 17:00 vendor.js
          
        # ls -lh : get the size in human readable format 
        -rw-r--r--   1 michaelzheng  staff   4.6M  Jul vendor.js 
        
    • Loading the vendor.js directly through browser or curl works perfectly.

    Debug

    • Find the location of nginx config file(i.e. nginx.conf)

      nginx -t
      
    • Find the location of error log, which is usually defined in nginx.conf

    • Check out the error

      # tail -f nginx
      2018/07/02 22:29:27 [crit] 14586#0: *3641 open() "/usr/local/var/run/nginx/proxy_temp/1/08/0000000081" failed
      (13: Permission denied) while reading upstream, client: 127.0.0.1, server: nginx.example.com, request: "GET /dist/js/vendor.js HTTP/1.1", 
      upstream: "http://127.0.0.1:8080/dist/js/vendor.js", host: "nginx.example.com", referrer: "http://nginx.example.com/testabc"
      

      Now that we can clearly see it's related to permission problem of the buffer directory proxy_temp.

    Solutions

    • Solution 1 - Grant permission

      chown -R nobody:admin proxy_temp
      

      You need to first run the command ps aux | grep nginx to find out the owner of the nginx process which is usually nobody

    • Solution 2 - Disable buffering with proxy_buffering set to off

    • Solution 3 - Change the buffer directory to other directory the nginx process owner has permission to, with proxy_temp_path directive.

    Notice

    • If you want to follow the latest news/articles for the series of my blogs, Please 「Watch」to Subscribe.

    相关文章

      网友评论

          本文标题:Step over nginx buffer issue

          本文链接:https://www.haomeiwen.com/subject/eevruftx.html