Server Version#: 1.32.7.7621
Player Version#: irrelevant
If my language comes across as impolite, I apologize—I’m not a native English speaker and I’m using a translator.
My Plex Media Server is running based on the LinuxServer‘s Plex image for years, and I use nginx as reverse proxy to provide secure HTTPS connections. Recently, I saw the following error logs in nginx:
2023/11/16 11:53:11 [error] 22#22: *3423 upstream sent duplicate header line: "Content-Length: 127136", previous value: "Content-Length: 127136" while reading response header from upstream, client: <hidden>, server: <hidden>, request: "GET /library/streams/338304?X-Plex-Token=<hidden>&encoding=utf-8" HTTP/1.1", upstream: "http://172.18.0.118:32400/library/streams/338304?X-Plex-Token=<hidden>:&encoding=utf-8"", host: "<hidden>:4880"
I believe it’s streaming my external subtitles. The Content-Length number confirms this (I used the wc -c command on that external subtitle and got the exact same number).
I observed responses from nginx, found a 502 Bad Gateway, by capturing packets on the client side (iOS and MacOS). In order to obtain more information, I examined the traffic between nginx (172.18.0.100) and the Plex server (172.18.0.118). Here are specific traffic details captured through tcpdump.
11:53:11.600211 veth79528c8 Out IP 172.18.0.100.41680 > 172.18.0.118.32400: Flags [P.], seq 1:377, ack 1, win 251, options [nop,nop,TS val 5
54843270 ecr 1155785302], length 376
E...7/@.@......d...v..~.&.%...r.....Z......
!.<.D..VGET /library/streams/338304?X-Plex-Token=<hidden>&encoding=utf-8 HTTP/1.1
Connection: close
Host:<hidden>
X-Real-IP: <hidden>
Forwarded: for=<hidden>
X-Forwarded-For: <hidden>
X-Forwarded-Proto: https
X-Forwarded-Host: <hidden>
X-Forwarded-Port: 4880
User-Agent: libmpv
Accept: */*
Range: bytes=0-
Icy-MetaData: 1
<and more....>
11:53:11.604333 veth59f162d Out IP 172.18.0.118.32400 > 172.18.0.100.41680: Flags [P.], seq 1:7241, ack 377, win 249, options [nop,nop,TS va
l 1155785306 ecr 554843270], length 7240
E..|.+@.@.@R...v...d~.....r.&.'o....um.....
D..Z!.<.HTTP/1.1 206 Partial Content
X-Plex-Protocol: 1.0
Content-Length: 127136
Content-Type: text/html
Content-Range: bytes 0-127135/127136
Connection: close
Content-Length: 127136
Cache-Control: no-cache
Date: Thu, 16 Nov 2023 03:53:11 GMT
...[Script Info]
; Script generated by Aegisub 3.2.2
; http://www.aegisub.org/
Title: ...............
Original Script: ShinY
Synch Point: 0
ScriptType: v4.00+
PlayResX: 1280
PlayResY: 720
Timer: 100.0000
YCbCr Matrix: TV.601
<and more....>
It’s evident that the Plex server indeed sent two lines of Content-Length in the header. I think this is causing Nginx to return a 502 error response. Yet, in my attempt to replicate this using the curl command, I discovered that the server sends the duplicated Content-Length header only when the client includes Range: bytes=0- in the request’s header. (Initially, without sending this header, the server correctly provided the subtitle content, leading to some confusion on me. However, upon including this header, an error occurred.)
The following command shows how I reproduced this error.
curl -v 'https://<hidden>:4880/library/streams/338304\?X-Plex-Token\=<hidden>&encoding=utf-8' -H "Range: bytes=0-"
The odd part is that even though the same error occurs, the Plex client on my MacOS shows subtitles normally. However, on iOS, it’s not working. It indicates the presence of an external subtitle, but selecting it doesn’t display any subtitles, and the client doesn’t show any errors.
In case anyone need, I put those error log lines for the Plex iOS client here. If you require additional information regarding those lines, please inform me.
(4148855) 🔧 PMKMPVClient.m:519 | [mkv] v: seek done
(4148832) ⚠️ PMKMPVClient.m:507 | [ffmpeg] warn: https: HTTP error 502 Bad Gateway
(4148860) ❌ PMKMPVClient.m:503 | [stream] error: Failed to open https://<hidden>:4880/library/streams/338304?X-Plex-Language=zh-CN&X-Plex-Device-Name=iPhone&X-Plex-Language=zh-CN&X-Plex-Device-Name=iPhone&X-Plex-Supported-Commands=abort%2CchangeQuality&X-Plex-Device-Screen-Density=2&X-Plex-Device=iPhone&X-Plex-Platform=iOS&X-Plex-Sync-Version=2&X-Plex-Token=xxxxx&X-Plex-Playback-Id=A1835D7E-2E84-4EF4-9FF8-3F3BE11E795F&X-Plex-Username=NobeKanai&X-Plex-Provides=client%2Ccontroller%2Csync-target%2Cplayer%2Cpubsub-player%2Cprovider-playback&X-Plex-Version=8.27&X-Plex-Client-Platform=iOS&X-Plex-Model=12%2C1&X-Plex-Session-Id=004067B7-A5FC-4352-980C-48F6D9CA13E8&X-Plex-Product=Plex%20for%20iOS&X-Plex-Client-Identifier=EF1E3E2E-0B51-4F7A-9BB8-5B8E6FC784B0&X-Plex-Playback-Session-Id=D45172CF-CC0F-45B3-BFFA-CBDBB9742B99&X-Plex-Drm=fairplay%3Avideo&X-Plex-Device-Screen-Resolution=828x1792&X-Plex-Device-Vendor=Apple&X-Plex-Platform-Version=17.1.1&X-Plex-Http-Pipeline=infinite&encoding=utf-8.
(4148860) ❌ PMKMPVClient.m:503 | [cplayer] error: Can not open external file https://<hidden>:4880/library/streams/338304?X-Plex-Language=zh-CN&X-Plex-Device-Name=iPhone&X-Plex-Language=zh-CN&X-Plex-Device-Name=iPhone&X-Plex-Supported-Commands=abort%2CchangeQuality&X-Plex-Device-Screen-Density=2&X-Plex-Device=iPhone&X-Plex-Platform=iOS&X-Plex-Sync-Version=2&X-Plex-Token=xxxxx&X-Plex-Playback-Id=A1835D7E-2E84-4EF4-9FF8-3F3BE11E795F&X-Plex-Username=NobeKanai&X-Plex-Provides=client%2Ccontroller%2Csync-target%2Cplayer%2Cpubsub-player%2Cprovider-playback&X-Plex-Version=8.27&X-Plex-Client-Platform=iOS&X-Plex-Model=12%2C1&X-Plex-Session-Id=004067B7-A5FC-4352-980C-48F6D9CA13E8&X-Plex-Product=Plex%20for%20iOS&X-Plex-Client-Identifier=EF1E3E2E-0B51-4F7A-9BB8-5B8E6FC784B0&X-Plex-Playback-Session-Id=D45172CF-CC0F-45B3-BFFA-CBDBB9742B99&X-Plex-Drm=fairplay%3Avideo&X-Plex-Device-Screen-Resolution=828x1792&X-Plex-Device-Vendor=Apple&X-Plex-Platform-Version=17.1.1&X-Plex-Http-Pipeline=infinite&encoding=utf-8.