nginx
use nginx to forward traffic to server and web client
- [ ] figure out how to enable/disable autosetup server url
- [ ] update readme
- [ ] proxy timeouts ?
- [ ] make sure there is backwards compatibility (for https on server )
- [ ] add tests for autosetup server url
latest code pushed to
ghcr.io/tsaridas/stremio-docker:development
Hey, first thank you for your work :) Is there a release date or something else on when this will be released?
I have seen some issues with server behind nginx and il not quite sure if it’s because of my environment or something else so until im sure nothing will break I cannot promise something. You could test the image I have im GitHub repo and test yourself .
Since I commented I use this image:
ghcr.io/tsaridas/stremio-docker:testing@sha256:2143eaaf6468d2a958f3e9d3d9625622fe1bb24d87dc29327d9dfa3508537269
Haven't noticed anything yet
ghcr.io/tsaridas/stremio-docker:development
I've updated the tag. I noticed that the last commit hasn't been published to the registry maybe you can fix that.
Also is there a list or some issues you noticed?
Updated Tag to:
ghcr.io/tsaridas/stremio-docker:development@sha256:7055123baf0aa7cdea5f06cd0f9a3b4e664a9021c977365dd182ea0ff8f58ebf
Thanks for checking. I’m not quite sure when I left it off. Main issue I saw was streaming issues and besides video getting downloaded correctly it was hanging from time to time. I’ll try to check if latest image was working correctly and it didn’t have any nginx config issues.
Okay I'll wait for the workflow to finish and hopefully succeed. Tomorrow I'll do some test.
I tried the same using caddy and your "normal" image. It worked fine without any stutters.
Also is there a list or some issues you noticed?
comparing the headers with nginx and direct server setup
Server: nginx
Date: Wed, 12 Mar 2025 18:34:53 GMT
Content-Type: video/mp4
Content-Length: 3364355
Connection: keep-alive
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 116846
Content-Type: video/mp4
Date: Wed, 12 Mar 2025 17:03:20 GMT
Keep-Alive: timeout=5
you see that Keep-Alive: timeout=5 is missing from nginx. I belive this might cause the video/audio to stop. This header should be passed from the server directly and not sure why it doesn't pass it when it goes behind nginx. You can also see Access-Control-Allow-Origin being passed but I doubt this causes an issue.
I think I found something:
- nginx uses http1.0 for backend connections (I think at least)
- nginx reuses tcp connections to the backend
To adress the http issue we can try this:
proxy_http_version 1.1;
# Not sure if this is needed but I saw a few times
proxy_set_header Connection "";
To proxy the keep-alive header:
proxy_pass_header Keep-Alive;
Give me a sec and I'll send you an updated config you can try
Maybe something like this could fix it?
server {
listen 80;
listen 8080;
server_name _; # Catch-all server name
access_log /dev/stdout;
error_log /dev/stderr warn;
# Compressions
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_http_version 1.1;
gzip_comp_level 4;
gzip_min_length 256;
gzip_types
application/json
application/javascript
application/xml
application/vnd.apple.mpegurl # HLS playlists
text/css
text/javascript
text/plain
text/vtt # Subtitles
text/xml;
proxy_set_header Accept-Encoding "gzip";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Origin $http_origin;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass_header Keep-Alive;
proxy_cache off;
proxy_buffering off;
proxy_max_temp_file_size 0;
limit_req_status 429;
error_page 401 = @error401;
location @error401 {
limit_req zone=auth burst=3 nodelay;
return 401;
}
# Stremio-specific routes
location ~ ^/(hlsv2|casting|local-addon|proxy|rar|zip|settings|create|removeAll|samples|probe|subtitlesTracks|opensubHash|subtitles|network-info|device-info|get-https|hwaccel-profiler|status|exec|stream|heartbeat|yt|tracks) {
include /etc/nginx/auth.conf;
proxy_pass http://127.0.0.1:11470;
}
location ~ ^/([^/]+)/(stats\.json|create|remove|destroy|burn) {
include /etc/nginx/auth.conf;
proxy_pass http://127.0.0.1:11470;
}
location ~ "^/([a-zA-Z0-9]{40})/([0-9]+)$" {
# doesn't work with auth
# include /etc/nginx/auth.conf;
proxy_pass http://127.0.0.1:11470;
}
location ~ ^/([^/]+)/([^/]+)/(stats\.json|hls\.m3u8|master\.m3u8|stream\.m3u8|dlna|thumb\.jpg) {
include /etc/nginx/auth.conf;
proxy_pass http://127.0.0.1:11470;
}
location ~ ^/([^/]+)/([^/]+)/(stream-q-[^/]+\.m3u8|stream-[^/]+\.m3u8|subs-[^/]+\.m3u8|mp4stream-q-[^/]+\.m3u8|mp4stream-q-[^/]+/[^/]+\.mp4) {
include /etc/nginx/auth.conf;
proxy_pass http://127.0.0.1:11470;
}
location ~ ^/([^/]+)/([^/]+)/(stream-q-[^/]+|stream-[^/]+)/[^/]+\.(ts|mp4) {
include /etc/nginx/auth.conf;
proxy_pass http://127.0.0.1:11470;
}
location = /(thumb\.jpg|stats\.json) {
include /etc/nginx/auth.conf;
proxy_pass http://127.0.0.1:11470;
}
location /manifest.json {
# Somehow this doesn't work well with auth.
# include /etc/nginx/auth.conf;
root /srv/stremio-server/build;
}
location / {
include /etc/nginx/auth.conf;
root /srv/stremio-server/build;
index index.html index.htm;
try_files $uri $uri/ /index.html;
location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2)$ {
expires 7d;
add_header Cache-Control "public, no-transform";
}
}
}
I really do not have a lot of experience with nginx...
We could also try another approach:
- Let nginx keep a specific amount of connections idle (like 16 or 32) to stremio
- this would reduce tcp handshake overhead
- send our own keep-alive headers and transmit video and audio segments like this
I am not sure if this will work or can work just an idea I have
I pushed some new changes, seems to work better for me now. if you could also test as well to make sure there are no issues. thank you for the help
Yeah will do that tomorrow.
Also we could define two global Proxy backends to reduce code duplication but Thats more like a clean up. Just Wanted to mention it
Yeah will do that tomorrow.
Also we could define two global Proxy backends to reduce code duplication but Thats more like a clean up. Just Wanted to mention it
Lets try to get this working and then I'm happy to discuss any other changes.
I have some test results.
TLDR: Works fine
Long Version: Downloading and streaming is seamless but I've noticed a small jitter in download speeds (around 10%). But I think that is an issue with my server or my internet connection as I have the same issue when downloading the same movie from my nextcloud.
But downloading and streaming are fine. No noticable changes. Even with the jitter the total download time has only increased by 1% so I'll say that's measure tolerance.
In the last 3days I ran through ~50GB of Data using your docker image. Still no issues
In the last 3days I ran through ~50GB of Data using your docker image. Still no issues
I figured the issues I had was the my browser. I'll try to get this PR moving.
Any suggestions welcome.
Yeah I would use upstream in the nginx config to reduce code duplication.
Like this:
- define a server and frontend like:
upstream backend {
server 127.0.0.1:11470;
keepalive 32;
}
Here should go all custom configuration we use
This can then be used like:
location ~ ^/ {
proxy_pass http://backend;
}
Other then that I currently have none and this just an optional clean-up.
If you have any other issues or I can help in any other way just let me know. :)
Let me know if I should test anything
I am still using it almost every day
@DenuxPlays I was just going to sent you a message to test and I saw your message :) I think I'm done. Just one small thing to update the release and nightly pipelines. You can take a look at the whole code if you are up to it. thank you in advance !
Log messages are wrong
Log messages are wrong
those are from stremio server not the startup script.
Ahh okay Everything else seems to work