測試環境 nginx 時好時壞的no live upstreams while connecting

環境描述:測試環境LNMP 因爲後端是php編寫,所以在nginx 配置文件裏

 upstream common{
          server 127.0.0.1:9000;
          server 127.0.0.1:9001;
          server 127.0.0.1:9002;
     }

客戶端發現兩個接口一個一直再報502,一個再報502和500 .然後就開始排查開發模式的DBUG

發現的確存在500現象,但是沒有產生502的問題。

然後就怕查到nginx 錯誤日誌裏面顯示:

[error] 7098#7098: *1537 no live upstreams while connecting to upstream

好像是後端程序時斷時好。但是很奇怪,好多測試環境同樣的配置文件都沒問題

然後參考了

https://blog.51cto.com/xiaosu/1689992 文章發現後端會話的問題。

因爲後端的開發沒有讓我負責測試環境的nginx配置文件的添加

排查配置文件發現

location ~ .php$ {
    expires 60s;
    fastcgi_pass   common;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
 }

文件編寫根據nginx提示負載均衡錯誤發現nginx配置文件存在一定的問題。爲了驗證我自己的想法更改了。nginx 配置文件如下:

location ~ .php$ {
          expires -1;
          #fastcgi_pass   common;
          fastcgi_pass 127.0.0.1:9002;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;

          #fastcgi_cache   ngx_fcgi_cache;
          fastcgi_cache_valid 200 302 5m;
          fastcgi_cache_valid 301 5m;
          fastcgi_cache_valid any 1m;
          fastcgi_cache_bypass $skip_cache;
          fastcgi_no_cache $skip_cache;
          fastcgi_cache_min_uses  1;  
          fastcgi_cache_methods  GET HEAD;
          fastcgi_cache_use_stale error  timeout invalid_header http_500;
          fastcgi_cache_key "$scheme$request_method$request_uri";
      }

通過測試發現502問題沒有在現。然後500問題提交給後端開發同事解決

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章