Welcome! Log In Create A New Profile

Advanced

seek function mp4 nginx | reverse proxy

Posted by Malandro 
seek function mp4 nginx | reverse proxy
December 15, 2020 10:29AM
The current configuration allows us to reverse proxy + cache a certain server with video content (mp4).
The problem we have is in the seek function (go back and forth through the player on the video), this in fact takes 1-2 minutes before resuming the stream.
How can we solve this problem?


nginx.conf

```
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
pcre_jit on;

events {
worker_connections 8096;
use epoll;
accept_mutex on;
multi_accept on;
}

thread_pool mp4Cache threads=4;

http {
##
# Basic Settings
##

sendfile on;
sendfile_max_chunk 512k;
tcp_nopush on;
tcp_nodelay on;
reset_timedout_connection on;
keepalive_timeout 15;
types_hash_max_size 2048;

open_file_cache max=30000 inactive=5m;
open_file_cache_valid 2m;
open_file_cache_min_uses 1;
open_file_cache_errors on;

gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_disable "msie6";
gzip_vary on;
gzip_types application/json application/vnd.apple.mpegurl;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Caching & Proxy
##

proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=mp4Cache:500m inactive=48h max_size=1800G use_temp_path=off;
proxy_cache_valid 200 500m;
proxy_set_header Range $slice_range;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_ignore_headers X-Accel-Expires X-Accel-Buffering Cache-Control Set-Cookie;
proxy_cache mp4Cache;
proxy_set_header X-Real-IP $http_cf_connecting_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
```

default conf

```
server {
server_name XXX;

set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2c0f:f248::/32;
set_real_ip_from 2a06:98c0::/29;
real_ip_header CF-Connecting-IP;

location /secure {
secure_link $arg_s;
secure_link_md5 "secret $remote_addr";
if ( $secure_link = "" ) { return 403; }

rewrite ^/secure/(.*)$ /$1;
}

location / {
internal;
mp4;
slice 20m;
aio threads=mp4Cache;
aio_write on;

#mp4;
proxy_pass https://XX.XX.XX.XX$uri;
proxy_set_header Host $host;
proxy_buffering on;
proxy_pass_request_headers on;
proxy_set_header X-Real-IP $http_cf_connecting_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

##
# Caching
##
#proxy_cache mp4Cache;
#proxy_cache_lock on;
proxy_cache_key $uri;
#proxy_cache_lock_age 24h;
#proxy_cache_use_stale updating;

##
# Disabling Cookies
##
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
}

##
# SSL
##

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/XXX/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/XXX/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = XXX) {
return 301 https://$host$request_uri;
} # managed by Certbot


listen 80;

server_name XXX;
return 404; # managed by Certbot
}
```
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 77
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready