Преглед на файлове

nginx: avoid proxy_pass to hosts other than JVB

Aaron van Meerten преди 3 години
родител
ревизия
f873cda197
променени са 2 файла, в които са добавени 8 реда и са изтрити 1 реда
  1. 2 1
      web/rootfs/defaults/meet.conf
  2. 6 0
      web/rootfs/etc/cont-init.d/10-config

+ 2 - 1
web/rootfs/defaults/meet.conf

@@ -1,5 +1,6 @@
 {{ $ENABLE_COLIBRI_WEBSOCKET := .Env.ENABLE_COLIBRI_WEBSOCKET | default "1" | toBool }}
 {{ $ENABLE_XMPP_WEBSOCKET := .Env.ENABLE_XMPP_WEBSOCKET | default "1" | toBool }}
+{{ $WS_SERVER_ID := .Env.JVB_WS_SERVER_ID | default .Env.JVB_WS_SERVER_ID_FALLBACK -}}
 
 server_name _;
 
@@ -48,7 +49,7 @@ location ~ ^/(libs|css|static|images|fonts|lang|sounds|connection_optimization|.
 {{ if $ENABLE_COLIBRI_WEBSOCKET }}
 # colibri (JVB) websockets
 location ~ ^/colibri-ws/([a-zA-Z0-9-\.]+)/(.*) {
-    proxy_pass http://$1:9090/colibri-ws/$1/$2$is_args$args;
+    proxy_pass http://{{ $WS_SERVER_ID }}:9090/colibri-ws/$1/$2$is_args$args;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";

+ 6 - 0
web/rootfs/etc/cont-init.d/10-config

@@ -63,6 +63,12 @@ if [[ $DISABLE_HTTPS -ne 1 ]]; then
     fi
 fi
 
+# On environments like Swarm the IP address used by the default gateway need not be
+# the one used for inter-container traffic. Use that one for our fallback ID.
+XMPP_SERVER_IP=$(dig +short ${XMPP_SERVER})
+# export this here to ensure JVB and nginx are in sync about websocket proxy host
+export JVB_WS_SERVER_ID_FALLBACK=$(ip route get ${XMPP_SERVER_IP} | grep -oP '(?<=src ).*' | awk '{ print $1 '})
+
 # copy config files
 tpl /defaults/nginx.conf > /config/nginx/nginx.conf