Nginx

nginx 不穩定錯誤“111:提供影片文件時連接被拒絕”

  • February 12, 2021

我有這台伺服器,一台 debian 10 arm64 機器,我在其上託管了一個 asp core 3.1 影片流網站。

總的來說,它工作得很好,除了有時在播放影片時,由於某種原因,nginx 會生成很多:

*258 connect() failed (111: Connection refused) while connecting to upstream

提供一些影片文件時。

現在這特別奇怪,因為:

  • 儘管影片已成功載入和播放,但我仍然記錄了此錯誤
  • 有時,我的系統似乎崩潰了——大概是由於這種行為(因為當 nginx 服務停止時不會發生這種崩潰)——最終變成完全只讀的。然後我必須重新啟動它才能恢復。

這是我的配置:

server {

   listen 443;
   server_name videocloud.my-domain.com;
   ssl_certificate /etc/letsencrypt/live/videocloud.my-domain.com/fullchain.pem; # managed by Certbot
   ssl_certificate_key /etc/letsencrypt/live/videocloud.my-domain.com/privkey.pem; # managed by Certbot

   ssl on;
   ssl_session_cache  builtin:1000  shared:SSL:10m;
   ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
   ssl_prefer_server_ciphers on;

   auth_basic            "Restricted Area";
   auth_basic_user_file      /etc/apache2/.htpasswd;

   add_header Access-Control-Expose-Headers Accept-Ranges;
   add_header Access-Control-Allow-Origin *;
   add_header Access-Control-Allow-Origin [http://localhost:5002];
   add_header Access-Control-Expose-Headers Accept-Ranges;
   add_header Access-Control-Expose-Headers Content-Encoding;
   add_header Access-Control-Expose-Headers Content-Length;
   add_header Access-Control-Expose-Headers Content-Range;
   add_header accept_ranges bytes;

   proxy_force_ranges on;

   location / {

     proxy_set_header        Host $host;
     proxy_set_header        X-Real-IP $remote_addr;
     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header        X-Forwarded-Proto $scheme;

     # Fix the It appears that your reverse proxy set up is broken" error.
     proxy_pass          http://localhost:5002;
     proxy_read_timeout  90;

     proxy_redirect      http://localhost:5002 https://videocloud.my-domain.com;
   }

}

正如上面評論中所建議的,通過用 127.0.0.1 替換 localhost 並禁用 ipv6 解決了這個問題

引用自:https://unix.stackexchange.com/questions/633483