|
@@ -116,13 +116,30 @@ elif [ "$1" = 'zammad-nginx' ]; then
|
|
|
check_zammad_ready
|
|
|
|
|
|
# configure nginx
|
|
|
+
|
|
|
+ # Ensure that nginx has a short TTL so that recreated containers with new IP addresses are found.
|
|
|
+ NAMESERVER=$(grep "nameserver" < /etc/resolv.conf | awk '{print $2}')
|
|
|
+ echo "resolver $NAMESERVER valid=5s;" > /etc/nginx/conf.d/resolver.conf
|
|
|
+
|
|
|
+ # Inject docker related settings into the nginx configuration.
|
|
|
+ #
|
|
|
+ # There is a workaround needed to support DNS resolution of upstream container names with short TTL:
|
|
|
+ # we set the proxy pass directly with a variable including the URL (!), rather than just referring to the
|
|
|
+ # upstream {} definition. For details, see https://tenzer.dk/nginx-with-dynamic-upstreams/.
|
|
|
sed -e "s#\(listen\)\(.*\)80#\1\2${NGINX_PORT}#g" \
|
|
|
-e "s#proxy_set_header X-Forwarded-Proto .*;#proxy_set_header X-Forwarded-Proto ${NGINX_SERVER_SCHEME};#g" \
|
|
|
- -e "s#server .*:3000#server ${ZAMMAD_RAILSSERVER_HOST}:${ZAMMAD_RAILSSERVER_PORT}#g" \
|
|
|
- -e "s#server .*:6042#server ${ZAMMAD_WEBSOCKET_HOST}:${ZAMMAD_WEBSOCKET_PORT}#g" \
|
|
|
+ -e "s#proxy_pass http://zammad-railsserver;#set \$zammad_railsserver_url http://${ZAMMAD_RAILSSERVER_HOST}:${ZAMMAD_RAILSSERVER_PORT}; proxy_pass \$zammad_railsserver_url;#g" \
|
|
|
+ -e "s#proxy_pass http://zammad-websocket;#set \$zammad_websocket_url http://${ZAMMAD_WEBSOCKET_HOST}:${ZAMMAD_WEBSOCKET_PORT}; proxy_pass \$zammad_websocket_url;#g" \
|
|
|
-e "s#server_name .*#server_name ${NGINX_SERVER_NAME};#g" \
|
|
|
-e 's#/var/log/nginx/zammad.\(access\|error\).log#/dev/stdout#g' < contrib/nginx/zammad.conf > /etc/nginx/sites-enabled/default
|
|
|
|
|
|
+ #
|
|
|
+ # Once we can use an nginx version >= 1.27.3, we can drop the proxy_pass workaround above and
|
|
|
+ # use the new dedicated syntax for configuring resolver usage on the upstream definitions directly:
|
|
|
+ #
|
|
|
+ #-e "s#server .*:3000#server ${ZAMMAD_RAILSSERVER_HOST}:${ZAMMAD_RAILSSERVER_PORT} resolve#g" \
|
|
|
+ #-e "s#server .*:6042#server ${ZAMMAD_WEBSOCKET_HOST}:${ZAMMAD_WEBSOCKET_PORT} resolve#g" \
|
|
|
+
|
|
|
echo "starting nginx..."
|
|
|
|
|
|
exec /usr/sbin/nginx -g 'daemon off;'
|