Step over nginx buffer issue

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.
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,180评论 0 10
  • 1. 块级元素和行内元素分别有哪些?动手测试并列出4条以上的特性区别 区别 块级元素默认会占据一整行,默认情况下其...
    头大如牛阅读 1,391评论 0 0
  • 看 球 文/中流击水 小小的球吸引了多少双眼睛 有人为之欢呼有人却为之泪奔 球星与球迷共同演绎着一网情深
    楚山汉水阅读 3,610评论 12 14
  • lineBreakMode: NSLineBreakByWordWrapping = 0 //以空格为边界,保留单...
    奋斗的郅博阅读 2,563评论 0 0
  • 有感 深夜,想着在家和学校不同的自己... 总觉得家里尝尝只有自己一个人,大多时候是没有人跟自己说话的,好像也就因...
    只是想起大漠阅读 1,265评论 0 0

友情链接更多精彩内容