From 6facf6a324bbcd53f5bf1fde0cd596bbdda98489 Mon Sep 17 00:00:00 2001 From: sadnub Date: Mon, 6 Sep 2021 12:54:37 -0400 Subject: [PATCH] fix nginx on docker dev --- .devcontainer/docker-compose.yml | 1 + .../containers/tactical-nginx/entrypoint.sh | 36 +++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 17ca0f1b..611f9b17 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -210,6 +210,7 @@ services: APP_PORT: ${APP_PORT} API_PORT: ${API_PORT} API_PROTOCOL: ${API_PROTOCOL} + DEV: 1 networks: dev: ipv4_address: ${DOCKER_NGINX_IP} diff --git a/docker/containers/tactical-nginx/entrypoint.sh b/docker/containers/tactical-nginx/entrypoint.sh index a2745aea..0992182c 100644 --- a/docker/containers/tactical-nginx/entrypoint.sh +++ b/docker/containers/tactical-nginx/entrypoint.sh @@ -5,7 +5,7 @@ set -e : "${WORKER_CONNECTIONS:=2048}" : "${APP_PORT:=80}" : "${API_PORT:=80}" -: "${API_PROTOCOL:=}" # blank for uwgsi +: "${DEV:=0}" CERT_PRIV_PATH=${TACTICAL_DIR}/certs/privkey.pem CERT_PUB_PATH=${TACTICAL_DIR}/certs/fullchain.pem @@ -29,6 +29,34 @@ fi /bin/bash -c "sed -i 's/worker_connections.*/worker_connections ${WORKER_CONNECTIONS};/g' /etc/nginx/nginx.conf" + +if [ $DEV -eq 1 ]; then + API_NGINX=" + #Using variable to disable start checks + set \$api http://tactical-backend:${API_PORT}; + proxy_pass \$api; + proxy_http_version 1.1; + proxy_cache_bypass \$http_upgrade; + + proxy_set_header Upgrade \$http_upgrade; + proxy_set_header Connection \"upgrade\"; + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto \$scheme; + proxy_set_header X-Forwarded-Host \$host; + proxy_set_header X-Forwarded-Port \$server_port; +" +else + API_NGINX=" + #Using variable to disable start checks + set \$api tactical-backend:${API_PORT}; + + include uwsgi_params; + uwsgi_pass \$api; +" +fi + nginx_config="$(cat << EOF # backend config server { @@ -37,11 +65,7 @@ server { server_name ${API_HOST}; location / { - #Using variable to disable start checks - set \$api ${API_PROTOCOL}tactical-backend:${API_PORT}; - - include uwsgi_params; - uwsgi_pass \$api; + ${API_NGINX} } location /static/ {