From bba2f4351865898a4f2ad446ad687be14236efd2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu>
Date: Fri, 13 Jul 2018 17:54:51 +0200
Subject: [PATCH] Changed CM Nginx proxy conf for MC (refs #25820).

---
 2.Common_services/5.Nginx/vhost_skyreach.conf | 27 ++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/2.Common_services/5.Nginx/vhost_skyreach.conf b/2.Common_services/5.Nginx/vhost_skyreach.conf
index 58992c94..56035a2c 100644
--- a/2.Common_services/5.Nginx/vhost_skyreach.conf
+++ b/2.Common_services/5.Nginx/vhost_skyreach.conf
@@ -1,3 +1,8 @@
+map $http_upgrade $connection_upgrade {
+	default upgrade;
+	'' close;
+}
+
 server {
 	listen 80;
 	server_name {{ server_name }};
@@ -45,11 +50,12 @@ server {
 		proxy_read_timeout 12h;
 	}
 
-	location /streaming/ {
-		# check requested path, only m3u8 and ts are allowed
+	location /proxy/ {
+		# proxy for MediaCoder UI and files
 		# ?: means that the group should not be stored as variable
-		location ~ ^/streaming/([\d\.\:]+)/((?:.+)\.(?:m3u8|ts)(?:\?.+)*)$ {
-			proxy_pass https://$1/$2;
+
+		# proxy for m3u8 and ts files with cache
+		location ~ ^/proxy/([\d\.\:]+)/(.+\.(?:m3u8|ts))$ {
 			proxy_cache livecache;
 			# do not consider secure urls as new files
 			proxy_cache_key $scheme$proxy_host$uri;
@@ -58,6 +64,19 @@ server {
 			# show if playlist or fragment has been cached from wowza
 			add_header X-Cache $upstream_cache_status;
 			# wowza is defining expiration headers (m3u8 is 1s, ts is 3600)
+			proxy_pass https://$1/$2;
+		}
+
+		# proxy for other urls including websocket
+		location ~ ^/proxy/([\d\.\:]+)/(.*)$ {
+			proxy_http_version 1.1;
+			proxy_buffering off;
+			# needed for websocket
+			proxy_set_header Upgrade $http_upgrade;
+			proxy_set_header Connection $connection_upgrade;
+			# change scheme of "Origin" to https
+			proxy_set_header Origin https://$1;
+			proxy_pass https://$1/$2;
 		}
 	}
 
-- 
GitLab