Switching to nginx 1.27 is there any difficulties?

Hi all, I came up with one idea against the background of all the errors that I see in peertube, I saw them on Nginx 1.22, but still that somehow it can be connected in a new way with the transition to Nginx 1.27. Is there any recommended version. It is clear that the config was compiled before version 1.25, since http2 is different in 1.25.

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;

на

server {
  listen 443 ssl;
  listen [::]:443 ssl;
  http2 on;

Могут ли сейчас ошибки эти Can't establish a connection to the server wss://angeltales.angellive.ru/tracker/socket - #6 par bestperson
Dans la version 6.2, je suis juste bombardé d’erreurs - #7 par bestperson
Последняя продолжает забрасывать ошибками, хоть и меньше и пользователи не жалуются, но они есть

warn[04.08.2024, 06:09:13] Client log: HLS.js error: mediaError - fatal: false - bufferStalledError
{
  "tags": [
    "client"
  ],
  "username": "raisabulkina2035",
  "userAgent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/25.0 Chrome/121.0.0.0 Mobile Safari/537.36",
  "url": "https://angeltales.angellive.ru/w/p/vGZp7a3isK9rNtydye4ro8?playlistPosition=57"
}
warn[04.08.2024, 06:09:59] Client log: HLS.js error: mediaError - fatal: false - bufferStalledError
{
  "tags": [
    "client"
  ],
  "username": "raisabulkina2035",
  "userAgent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/25.0 Chrome/121.0.0.0 Mobile Safari/537.36",
  "url": "https://angeltales.angellive.ru/w/p/vGZp7a3isK9rNtydye4ro8?playlistPosition=57"
}
warn[04.08.2024, 06:18:15] Client log: HLS.js error: mediaError - fatal: false - bufferStalledError
{
  "tags": [
    "client"
  ],
  "username": "raisabulkina2035",
  "userAgent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/25.0 Chrome/121.0.0.0 Mobile Safari/537.36",
  "url": "https://angeltales.angellive.ru/w/p/vGZp7a3isK9rNtydye4ro8?playlistPosition=57"
}
error[04.08.2024, 07:12:44] Client log: Cannot run hook action:video-watch.player.loaded of script /plugins/nocomments/2.1.0/client-scripts/client/video-watch-client-plugin.js of plugin nocomments
{
  "tags": [
    "client"
  ],
  "username": "raisabulkina2035",
  "userAgent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/25.0 Chrome/121.0.0.0 Mobile Safari/537.36",
  "stackTrace": "Cannot read properties of null (reading 'remove')\nTypeError: Cannot read properties of null (reading 'remove')\n    at handler (https://angeltales.angellive.ru/plugins/nocomments/2.1.0/client-scripts/client/video-watch-client-plugin.js:7:23)\n    at https://angeltales.angellive.ru/client/ru-RU/chunk-CEOCBFKL.js:11:55349\n    at Generator.next (<anonymous>)\n    at https://angeltales.angellive.ru/client/ru-RU/chunk-ODKBFOSP.js:1:1399\n    at new I (https://angeltales.angellive.ru/client/ru-RU/polyfills-DKLCR6XS.js:2:2267)\n    at F (https://angeltales.angellive.ru/client/ru-RU/chunk-ODKBFOSP.js:1:1219)\n    at yI (https://angeltales.angellive.ru/client/ru-RU/chunk-CEOCBFKL.js:11:55204)\n    at e.<anonymous> (https://angeltales.angellive.ru/client/ru-RU/chunk-CEOCBFKL.js:11:64189)\n    at Generator.next (<anonymous>)\n    at o (https://angeltales.angellive.ru/client/ru-RU/chunk-ODKBFOSP.js:1:1257)",
  "url": "https://angeltales.angellive.ru/w/p/vGZp7a3isK9rNtydye4ro8?playlistPosition=60&resume=true"
}
warn[04.08.2024, 07:12:47] Client log: HLS.js error: mediaError - fatal: false - bufferStalledError
{
  "tags": [
    "client"
  ],
  "username": "raisabulkina2035",
  "userAgent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/25.0 Chrome/121.0.0.0 Mobile Safari/537.36",
  "url": "https://angeltales.angellive.ru/w/p/vGZp7a3isK9rNtydye4ro8?playlistPosition=60&resume=true"
}
warn[04.08.2024, 09:10:39] Client log: HLS.js error: mediaError - fatal: false - bufferStalledError
{
  "tags": [
    "client"
  ],
  "username": "raisabulkina2035",
  "userAgent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/25.0 Chrome/121.0.0.0 Mobile Safari/537.36",
  "url": "https://angeltales.angellive.ru/w/p/kNEeFRJjFJa9LQRhB7ao16?playlistPosition=4"
}
warn[04.08.2024, 09:10:39] Client log: HLS.js error: mediaError - fatal: false - bufferNudgeOnStall
{
  "tags": [
    "client"
  ],
  "username": "raisabulkina2035",
  "userAgent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/25.0 Chrome/121.0.0.0 Mobile Safari/537.36",
  "url": "https://angeltales.angellive.ru/w/p/kNEeFRJjFJa9LQRhB7ao16?playlistPosition=4"
}
warn[04.08.2024, 09:17:45] Client log: HLS.js error: mediaError - fatal: false - bufferStalledError
{
  "tags": [
    "client"
  ],
  "username": "raisabulkina2035",
  "userAgent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/25.0 Chrome/121.0.0.0 Mobile Safari/537.36",
  "url": "https://angeltales.angellive.ru/w/p/vGZp7a3isK9rNtydye4ro8?playlistPosition=26"
}
warn[04.08.2024, 09:35:13] Client log: HLS.js error: mediaError - fatal: false - bufferStalledError
{
  "tags": [
    "client"
  ],
  "username": "raisabulkina2035",
  "userAgent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/25.0 Chrome/121.0.0.0 Mobile Safari/537.36",
  "url": "https://angeltales.angellive.ru/w/p/vGZp7a3isK9rNtydye4ro8?playlistPosition=44&resume=true"
}
error[04.08.2024, 11:06:18] Client log: HLS.js error: networkError - fatal: true - manifestLoadError
{
  "tags": [
    "client"
  ],
  "username": "nina2035",
  "userAgent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Mobile Safari/537.36",
  "meta": "{\"currentTime\":0,\"data\":{\"type\":\"networkError\",\"details\":\"manifestLoadError\",\"fatal\":true,\"url\":\"https://angeltales.angellive.ru/static/streaming-playlists/hls/private/03a38acd-ff10-4db3-a107-4d61f810791b/ace7089d-a8a0-448e-9613-ec138452c07b-master.m3u8\",\"loader\":{\"impl\":{\"segmentManager\":{\"masterPlaylist\":null,\"variantPlaylists\":{},\"segmentRequest\":null,\"playQueue\":[],\"settings\":{\"forwardSegmentCount\":50,\"swarmId\":\"https://angeltales.angellive.ru/static/streaming-playlists/hls/private/03a38acd-ff10-4db3-a107-4d61f810791b/ace7089d-a8a0-448e-9613-ec138452c07b-master.m3u8\"},\"loader\":{\"_events\":{\"segment_loaded\":[null,null],\"segment_error\":[null,null],\"segment_abort\":[null,null]},\"_eventsCount\":9,\"segmentsQueue\":[],\"bandwidthApproximator\":{\"lastBytes\":[],\"currentBytesSum\":0,\"lastBandwidth\":[]},\"httpDownloadInitialTimeoutTimestamp\":null,\"settings\":{\"cachedSegmentExpiration\":86400000,\"cachedSegmentsCount\":100,\"useP2P\":true,\"consumeOnly\":true,\"requiredSegmentsPriority\":3,\"skipSegmentBuilderPriority\":1,\"simultaneousHttpDownloads\":1,\"httpDownloadProbability\":0.06,\"httpDownloadProbabilityInterval\":1000,\"httpDownloadProbabilitySkipIfNoPeers\":true,\"httpFailedSegmentTimeout\":1000,\"httpDownloadMaxPriority\":9,\"httpDownloadInitialTimeout\":0,\"httpDownloadInitialTimeoutPerSegment\":4000,\"httpUseRanges\":false,\"simultaneousP2PDownloads\":3,\"p2pDownloadMaxPriority\":50,\"p2pSegmentDownloadTimeout\":60000,\"webRtcMaxMessageSize\":65535,\"trackerAnnounce\":[\"wss://angeltales.angellive.ru:443/tracker/socket\"],\"peerRequestsPerAnnounce\":10,\"rtcConfig\":{\"iceServers\":[{\"urls\":\"stun:stun.stunprotocol.org\"},{\"urls\":\"stun:stun.framasoft.org\"}]}},\"segmentsStorage\":{\"settings\":{\"cachedSegmentExpiration\":86400000,\"cachedSegmentsCount\":100,\"useP2P\":true,\"consumeOnly\":true,\"requiredSegmentsPriority\":3,\"skipSegmentBuilderPriority\":1,\"simultaneousHttpDownloads\":1,\"httpDownloadProbability\":0.06,\"httpDownloadProbabilityInterval\":1000,\"httpDownloadProbabilitySkipIfNoPeers\":true,\"httpFailedSegmentTimeout\":1000,\"httpDownloadMaxPriority\":9,\"httpDownloadInitialTimeout\":0,\"httpDownloadInitialTimeoutPerSegment\":4000,\"httpUseRanges\":false,\"simultaneousP2PDownloads\":3,\"p2pDownloadMaxPriority\":50,\"p2pSegmentDownloadTimeout\":60000,\"webRtcMaxMessageSize\":65535,\"trackerAnnounce\":[\"wss://angeltales.angellive.ru:443/tracker/socket\"],\"peerRequestsPerAnnounce\":10,\"rtcConfig\":{\"iceServers\":[{\"urls\":\"stun:stun.stunprotocol.org\"},{\"urls\":\"stun:stun.framasoft.org\"}]}},\"cache\":{}},\"httpManager\":{\"_events\":{},\"_eventsCount\":5,\"settings\":{\"cachedSegmentExpiration\":86400000,\"cachedSegmentsCount\":100,\"useP2P\":true,\"consumeOnly\":true,\"requiredSegmentsPriority\":3,\"skipSegmentBuilderPriority\":1,\"simultaneousHttpDownloads\":1,\"httpDownloadProbability\":0.06,\"httpDownloadProbabilityInterval\":1000,\"httpDownloadProbabilitySkipIfNoPeers\":true,\"httpFailedSegmentTimeout\":1000,\"httpDownloadMaxPriority\":9,\"httpDownloadInitialTimeout\":0,\"httpDownloadInitialTimeoutPerSegment\":4000,\"httpUseRanges\":false,\"simultaneousP2PDownloads\":3,\"p2pDownloadMaxPriority\":50,\"p2pSegmentDownloadTimeout\":60000,\"webRtcMaxMessageSize\":65535,\"trackerAnnounce\":[\"wss://angeltales.angellive.ru:443/tracker/socket\"],\"peerRequestsPerAnnounce\":10,\"rtcConfig\":{\"iceServers\":[{\"urls\":\"stun:stun.stunprotocol.org\"},{\"urls\":\"stun:stun.framasoft.org\"}]}},\"xhrRequests\":{},\"failedSegments\":{}},\"p2pManager\":{\"_events\":{},\"_eventsCount\":10,\"segmentsStorage\":{\"settings\":{\"cachedSegmentExpiration\":86400000,\"cachedSegmentsCount\":100,\"useP2P\":true,\"consumeOnly\":true,\"requiredSegmentsPriority\":3,\"skipSegmentBuilderPriority\":1,\"simultaneousHttpDownloads\":1,\"httpDownloadProbability\":0.06,\"httpDownloadProbabilityInterval\":1000,\"httpDownloadProbabilitySkipIfNoPeers\":true,\"httpFailedSegmentTimeout\":1000,\"httpDownloadMaxPriority\":9,\"httpDownloadInitialTimeout\":0,\"httpDownloadInitialTimeoutPerSegment\":4000,\"httpUseRanges\":false,\"simultaneousP2PDownloads\":3,\"p2pDownloadMaxPriority\":50,\"p2pSegmentDownloadTimeout\":60000,\"webRtcMaxMessageSize\":65535,\"trackerAnnounce\":[\"wss://angeltales.angellive.ru:443/tracker/socket\"],\"peerRequestsPerAnnounce\":10,\"rtcConfig\":{\"iceServers\":[{\"urls\":\"stun:stun.stunprotocol.org\"},{\"urls\":\"stun:stun.framasoft.org\"}]}},\"cache\":{}},\"settings\":{\"cachedSegmentExpiration\":86400000,\"cachedSegmentsCount\":100,\"useP2P\":true,\"consumeOnly\":true,\"requiredSegmentsPriority\":3,\"skipSegmentBuilderPriority\":1,\"simultaneousHttpDownloads\":1,\"httpDownloadProbability\":0.06,\"httpDownloadProbabilityInterval\":1000,\"httpDownloadProbabilitySkipIfNoPeers\":true,\"httpFailedSegmentTimeout\":1000,\"httpDownloadMaxPriority\":9,\"httpDownloadInitialTimeout\":0,\"httpDownloadInitialTimeoutPerSegment\":4000,\"httpUseRanges\":false,\"simultaneousP2PDownloads\":3,\"p2pDownloadMaxPriority\":50,\"p2pSegmentDownloadTimeout\":60000,\"webRtcMaxMessageSize\":65535,\"trackerAnnounce\":[\"wss://angeltales.angellive.ru:443/tracker/socket\"],\"peerRequestsPerAnnounce\":10,\"rtcConfig\":{\"iceServers\":[{\"urls\":\"stun:stun.stunprotocol.org\"},{\"urls\":\"stun:stun.framasoft.org\"}]}},\"trackerClient\":null,\"peers\":{},\"peerCandidates\":{},\"peerSegmentRequests\":{},\"streamSwarmId\":null,\"pendingTrackerClient\":null,\"peerId\":{}}}},\"stats\":{\"loaded\":0,\"total\":0,\"aborted\":false,\"retry\":0,\"chunkCount\":0,\"bwEstimate\":0,\"loading\":{\"start\":3811.100000023842,\"end\":0,\"first\":3811.100000023842},\"parsing\":{\"start\":0,\"end\":0},\"buffering\":{\"start\":0,\"end\":0,\"first\":0}},\"debugId\":\"\",\"context\":{\"id\":null,\"level\":0,\"responseType\":\"text\",\"type\":\"manifest\",\"url\":\"https://angeltales.angellive.ru/static/streaming-playlists/hls/private/03a38acd-ff10-4db3-a107-4d61f810791b/ace7089d-a8a0-448e-9613-ec138452c07b-master.m3u8\",\"deliveryDirectives\":null},\"callbacks\":{}},\"stats\":{\"loaded\":0,\"total\":0,\"aborted\":false,\"retry\":0,\"chunkCount\":0,\"bwEstimate\":0,\"loading\":{\"start\":3811.100000023842,\"end\":0,\"first\":3811.100000023842},\"parsing\":{\"start\":0,\"end\":0},\"buffering\":{\"start\":0,\"end\":0,\"first\":0}},\"context\":{\"id\":null,\"level\":0,\"responseType\":\"text\",\"type\":\"manifest\",\"url\":\"https://angeltales.angellive.ru/static/streaming-playlists/hls/private/03a38acd-ff10-4db3-a107-4d61f810791b/ace7089d-a8a0-448e-9613-ec138452c07b-master.m3u8\",\"deliveryDirectives\":null},\"callbacks\":{}},\"context\":{\"id\":null,\"level\":0,\"responseType\":\"text\",\"type\":\"manifest\",\"url\":\"https://angeltales.angellive.ru/static/streaming-playlists/hls/private/03a38acd-ff10-4db3-a107-4d61f810791b/ace7089d-a8a0-448e-9613-ec138452c07b-master.m3u8\",\"deliveryDirectives\":null},\"error\":{},\"stats\":{\"loaded\":0,\"total\":0,\"aborted\":false,\"retry\":0,\"chunkCount\":0,\"bwEstimate\":0,\"loading\":{\"start\":3811.100000023842,\"end\":0,\"first\":3811.100000023842},\"parsing\":{\"start\":0,\"end\":0},\"buffering\":{\"start\":0,\"end\":0,\"first\":0}}}}",
  "url": "https://angeltales.angellive.ru/w/1s4zrQm9apJstkHWRJD4Ec"
}

The current configuration has not changed

# Minimum Nginx version required:  1.13.0 (released Apr 25, 2017)
# Please check your Nginx installation features the following modules via 'nginx -V':
# STANDARD HTTP MODULES: Core, Proxy, Rewrite, Access, Gzip, Headers, HTTP/2, Log, Real IP, SSL, Thread Pool, Upstream, AIO Multithreading.
# THIRD PARTY MODULES:   None.

server {
  listen 80;
  listen [::]:80;
  server_name angeltales.angellive.ru;

  location /.well-known/acme-challenge/ {
    default_type "text/plain";
    root /var/www/certbot;
  }
  location / { return 301 https://$host$request_uri; }
}

upstream backend {
  server 127.0.0.1:9000;
}

server {
  listen 443 ssl;
  listen [::]:443 ssl;
  http2 on;
  server_name angeltales.angellive.ru;

  access_log /var/log/nginx/peertube.access.log; # reduce I/0 with buffer=10m flush=5m
  error_log  /var/log/nginx/peertube.error.log;

  ##
  # Certificates
  # you need a certificate to run in production. see https://letsencrypt.org/
  ##
  ssl_certificate     /etc/letsencrypt/live/angeltales.angellive.ru/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/angeltales.angellive.ru/privkey.pem;

  location ^~ '/.well-known/acme-challenge' {
    default_type "text/plain";
    root /var/www/certbot;
  }

  ##
  # Security hardening (as of Nov 15, 2020)
  # based on Mozilla Guideline v5.6
  ##

  ssl_protocols             TLSv1.2 TLSv1.3;
  ssl_prefer_server_ciphers on;
  ssl_ciphers               ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256; # add ECDHE-RSA-AES256-SHA if you want compatibility with Android 4
  ssl_session_timeout       1d; # defaults to 5m
  ssl_session_cache         shared:SSL:10m; # estimated to 40k sessions
  ssl_session_tickets       off;
  ssl_stapling              on;
  ssl_stapling_verify       on;
  # HSTS (https://hstspreload.org), requires to be copied in 'location' sections that have add_header directives
  #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";

  ##
  # Application
  ##

  location @api {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host            $host;
    proxy_set_header X-Real-IP       $remote_addr;

    client_max_body_size  100k; # default is 1M

    proxy_connect_timeout 10m;
    proxy_send_timeout    10m;
    proxy_read_timeout    10m;
    send_timeout          10m;

    proxy_pass http://backend;
  }

  location / {
    try_files /dev/null @api;
  }

  location ~ ^/api/v1/videos/(upload-resumable|([^/]+/source/replace-resumable))$ {
    client_max_body_size    0;
    proxy_request_buffering off;

    try_files /dev/null @api;
  }

  location ~ ^/api/v1/users/[^/]+/imports/import-resumable$ {
    client_max_body_size    0;
    proxy_request_buffering off;

    try_files /dev/null @api;
  }

  location ~ ^/api/v1/videos/(upload|([^/]+/studio/edit))$ {
    limit_except POST HEAD { deny all; }

    # This is the maximum upload size, which roughly matches the maximum size of a video file.
    # Note that temporary space is needed equal to the total size of all concurrent uploads.
    # This data gets stored in /var/lib/nginx by default, so you may want to put this directory
    # on a dedicated filesystem.
    client_max_body_size                      12G; # default is 1M
    add_header            X-File-Maximum-Size 8G always; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size)

    try_files /dev/null @api;
  }

  location ~ ^/api/v1/runners/jobs/[^/]+/(update|success)$ {
    client_max_body_size                      12G; # default is 1M
    add_header            X-File-Maximum-Size 8G always; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size)

    try_files /dev/null @api;
  }

  location ~ ^/api/v1/(videos|video-playlists|video-channels|users/me) {
    client_max_body_size                      6M; # default is 1M
    add_header            X-File-Maximum-Size 4M always; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size)

    try_files /dev/null @api;
  }

  ##
  # Websocket
  ##

  location @api_websocket {
    proxy_http_version 1.1;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   Host            $host;
    proxy_set_header   X-Real-IP       $remote_addr;
    proxy_set_header   Upgrade         $http_upgrade;
    proxy_set_header   Connection      "upgrade";

    proxy_pass http://backend;
  }

  location /socket.io {
    try_files /dev/null @api_websocket;
  }

  location /tracker/socket {
    # Peers send a message to the tracker every 15 minutes
    # Don't close the websocket before then
    proxy_read_timeout 15m; # default is 60s

    try_files /dev/null @api_websocket;
  }

  # Plugin websocket routes
  location ~ ^/plugins/[^/]+(/[^/]+)?/ws/ {
    try_files /dev/null @api_websocket;
  }

  ##
  # Performance optimizations
  # For extra performance please refer to https://github.com/denji/nginx-tuning
  ##

  root /var/www/peertube/storage;

  # Enable compression for JS/CSS/HTML, for improved client load times.
  # It might be nice to compress JSON/XML as returned by the API, but
  # leaving that out to protect against potential BREACH attack.
  gzip              on;
  gzip_vary         on;
  gzip_types        # text/html is always compressed by HttpGzipModule
                    text/css
                    application/javascript
                    font/truetype
                    font/opentype
                    application/vnd.ms-fontobject
                    image/svg+xml;
  gzip_min_length   1000; # default is 20 bytes
  gzip_buffers      16 8k;
  gzip_comp_level   2; # default is 1

  client_body_timeout       30s; # default is 60
  client_header_timeout     10s; # default is 60
  send_timeout              10s; # default is 60
  keepalive_timeout         10s; # default is 75
  resolver_timeout          10s; # default is 30
  reset_timedout_connection on;
  proxy_ignore_client_abort on;

  tcp_nopush                on; # send headers in one piece
  tcp_nodelay               on; # don't buffer data sent, good for small data bursts in real time

  # If you have a small /var/lib partition, it could be interesting to store temp nginx uploads in a different place
  # See https://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_temp_path
  #client_body_temp_path /var/www/peertube/storage/nginx/;

  # Bypass PeerTube for performance reasons. Optional.
  # Should be consistent with client-overrides assets list in client.ts server controller
  location ~ ^/client/(assets/images/(icons/icon-36x36\.png|icons/icon-48x48\.png|icons/icon-72x72\.png|icons/icon-96x96\.png|icons/icon-144x144\.png|icons/icon-192x192\.png|icons/icon-512x512\.png|logo\.svg|favicon\.png|default-playlist\.jpg|default-avatar-account\.png|default-avatar-account-48x48\.png|default-avatar-video-channel\.png|default-avatar-video-channel-48x48\.png))$ {
    add_header Cache-Control "public, max-age=31536000, immutable"; # Cache 1 year

    root /var/www/peertube;

    try_files /storage/client-overrides/$1 /peertube-latest/client/dist/$1 @api;
  }

  # Bypass PeerTube for performance reasons. Optional.
  location ~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$ {
    add_header Cache-Control "public, max-age=31536000, immutable"; # Cache 1 year

    alias /var/www/peertube/peertube-latest/client/dist/$1;
  }

  location ~ ^(/static/(webseed|web-videos|streaming-playlists/hls)/private/)|^/download {
    # We can't rate limit a try_files directive, so we need to duplicate @api

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

    proxy_limit_rate 5M;

    proxy_pass http://backend;
  }

  # Bypass PeerTube for performance reasons. Optional.
  location ~ ^/static/(webseed|web-videos|redundancy|streaming-playlists)/ {
    limit_rate_after            5M;

    set $peertube_limit_rate  5M;

    # Use this line with nginx >= 1.17.0
    limit_rate $peertube_limit_rate;
    # Or this line with nginx < 1.17.0
    # set $limit_rate $peertube_limit_rate;

    if ($request_method = 'OPTIONS') {
      add_header Access-Control-Allow-Origin  '*';
      add_header Access-Control-Allow-Methods 'GET, OPTIONS';
      add_header Access-Control-Allow-Headers 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header Access-Control-Max-Age       1728000; # Preflight request can be cached 20 days
      add_header Content-Type                 'text/plain charset=UTF-8';
      add_header Content-Length               0;
      return 204;
    }

    if ($request_method = 'GET') {
      add_header Access-Control-Allow-Origin  '*';
      add_header Access-Control-Allow-Methods 'GET, OPTIONS';
      add_header Access-Control-Allow-Headers 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

      # Don't spam access log file with byte range requests
      access_log off;
    }

    # Enabling the sendfile directive eliminates the step of copying the data into the buffer
    # and enables direct copying data from one file descriptor to another.
    sendfile on;
    sendfile_max_chunk 1M; # prevent one fast connection from entirely occupying the worker process. should be > 800k.
    aio threads;

    # web-videos is the name of the directory mapped to the `storage.web_videos` key in your PeerTube configuration
    rewrite ^/static/webseed/(.*)$ /web-videos/$1 break;
    rewrite ^/static/(.*)$         /$1        break;

    try_files $uri @api;
  }
}