【发布时间】:2020-04-16 03:53:20
【问题描述】:
我在同一个网络中有 3 个 docker 容器:
- Storage (golang) - 它提供了用于上传视频文件的 API。
- Streamer (nginx) - 流式传输上传的文件
- 反向代理(姑且称之为代理)
我在用户和代理之间有HTTPS 协议。
假设有一个文件 id=c14de868-3130-426a-a0cc-7ff6590e9a1f 并且用户想要查看它。所以用户向https://stream.example.com/hls/master.m3u8?id=c14de868-3130-426a-a0cc-7ff6590e9a1f 发出请求。 Streamer 知道视频 ID(来自查询参数),但它不知道视频的路径,因此它向存储发出请求并交换视频 ID 以获取视频路径。实际上它会将 proxy_pass 传递给http://docker-storage/getpath?id=c14de868-3130-426a-a0cc-7ff6590e9a1f。
上游服务器中的docker-storage。协议是http,因为 我在本地网络中的 docker 容器之间没有 SSL 连接。
Streamer 获得文件路径后,它开始流式传输。但是用户的浏览器开始抛出Mixed Content Type错误,因为第一个请求是抛出HTTPS,在proxy_pass之后它变成了HTTP。
这里是 nginx.conf 文件(它是一个 Streamer 容器):
worker_processes auto;
events {
use epoll;
}
http {
error_log stderr debug;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
vod_mode local;
vod_metadata_cache metadata_cache 16m;
vod_response_cache response_cache 512m;
vod_last_modified_types *;
vod_segment_duration 9000;
vod_align_segments_to_key_frames on;
vod_dash_fragment_file_name_prefix "segment";
vod_hls_segment_file_name_prefix "segment";
vod_manifest_segment_durations_mode accurate;
open_file_cache max=1000 inactive=5m;
open_file_cache_valid 2m;
open_file_cache_min_uses 1;
open_file_cache_errors on;
aio on;
upstream docker-storage {
# There is a docker container called storage on the same network
server storage:9000;
}
server {
listen 9000;
server_name localhost;
root /srv/static;
location = /exchange-id-to-path {
proxy_pass $auth_request_uri;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Original-URI $request_uri;
# I tried to experiment with this header
proxy_set_header X-Forwarded-Proto https;
set $filepath $upstream_http_the_file_path;
}
location /hls {
# I use auth_request module just to get the path from response header (The-File-Path)
set $auth_request_uri "http://docker-storage/getpath?id=$arg_id";
auth_request /exchange-id-to-path;
auth_request_set $filepath $upstream_http_the_file_path;
# Here I provide path to the file I want to stream
vod hls;
alias $filepath/$arg_id;
}
}
}
这是来自成功 (200) 请求的响应:
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1470038,RESOLUTION=1280x720,FRAME-RATE=25.000,CODECS="avc1.4d401f,mp4a.40.2"
http://stream.example.com/hls/index-v1-a1.m3u8
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=171583,RESOLUTION=1280x720,CODECS="avc1.4d401f",URI="http://stream.example.com/hls/iframes-v1-a1.m3u8"
问题是proxy_pass到http后如何保存https协议?
p.s.我使用Kaltura nginx-vod-module 流式传输视频文件。
【问题讨论】:
标签: nginx proxy stream proxypass kaltura