From f88ed3612d68228e08356082b45ef893be94b0e5 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Sat, 17 Feb 2018 17:56:17 +0100 Subject: [PATCH] [IMP]Nginx for Odoo : handle odoo.conf multiple hosts, server names --- odoo/nginx/Dockerfile | 1 + odoo/nginx/Dockerfile.dev | 1 + odoo/nginx/launch.sh | 28 ++++++++++++++++++++++++++++ odoo/nginx/odoo.conf | 16 ++++++++-------- 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 odoo/nginx/launch.sh diff --git a/odoo/nginx/Dockerfile b/odoo/nginx/Dockerfile index 1bc1ae0..fbae531 100644 --- a/odoo/nginx/Dockerfile +++ b/odoo/nginx/Dockerfile @@ -6,3 +6,4 @@ ENV ODOO_SERVER_NAMES odoo # Copy templates and usefull files COPY odoo.conf /etc/nginx/templates/ +COPY launch.sh /launch.sh diff --git a/odoo/nginx/Dockerfile.dev b/odoo/nginx/Dockerfile.dev index c112277..39ffbb7 100644 --- a/odoo/nginx/Dockerfile.dev +++ b/odoo/nginx/Dockerfile.dev @@ -6,3 +6,4 @@ ENV ODOO_SERVER_NAMES odoo # Copy templates and usefull files COPY odoo.conf.dev /etc/nginx/templates/odoo.conf +COPY launch.sh /launch.sh diff --git a/odoo/nginx/launch.sh b/odoo/nginx/launch.sh new file mode 100644 index 0000000..87f015a --- /dev/null +++ b/odoo/nginx/launch.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Needed for envsubst to replace $ in final rendering +export DOLLSIGN=$ + +# Bash templating +cd /etc/nginx/templates +for tpl in * ; do + if [ $tpl = "odoo.conf" ]; then + echo '' > /etc/nginx/conf/$tpl + index=0 + IFS=':' read -ra ODOO_SERVICE <<< "$ODOO_SERVICE" + IFS=':' read -ra ODOO_SERVER_NAMES <<< "$ODOO_SERVER_NAMES" + for service in "${ODOO_SERVICE[@]}" + do + SERVICE=${ODOO_SERVICE[$index]} + SERVER_NAMES=${ODOO_SERVER_NAMES[$index]} + export SERVICE SERVER_NAMES + envsubst < $tpl >> /etc/nginx/conf.d/$tpl + ((index++)) + done + else + envsubst < $tpl > /etc/nginx/conf.d/$tpl + fi +done + +# Nginx launch +nginx diff --git a/odoo/nginx/odoo.conf b/odoo/nginx/odoo.conf index af1cbc5..6bb3f87 100644 --- a/odoo/nginx/odoo.conf +++ b/odoo/nginx/odoo.conf @@ -1,20 +1,20 @@ -upstream ${ODOO_SERVICE}server { - server ${ODOO_SERVICE}:8069 fail_timeout=300s; +upstream ${SERVICE}server { + server ${SERVICE}:8069 fail_timeout=300s; } -upstream ${ODOO_SERVICE}longpoll { - server ${ODOO_SERVICE}:8072 fail_timeout=300s; +upstream ${SERVICE}longpoll { + server ${SERVICE}:8072 fail_timeout=300s; } server { listen ${NGINX_PORT}; - server_name ${ODOO_SERVER_NAMES}; + server_name ${SERVER_NAMES}; return 301 https://${DOLLSIGN}host:${NGINX_SSL_PORT}${DOLLSIGN}request_uri; } server { listen ${NGINX_SSL_PORT} ssl; - server_name ${ODOO_SERVER_NAMES}; + server_name ${SERVER_NAMES}; client_max_body_size 200M; gzip on; gzip_min_length 256; @@ -29,11 +29,11 @@ server { proxy_set_header X-Forwarded-Proto ${DOLLSIGN}scheme; proxy_set_header X-Real-IP ${DOLLSIGN}remote_addr; location / { - proxy_pass http://${ODOO_SERVICE}server; + proxy_pass http://${SERVICE}server; proxy_redirect off; # proxy_redirect http://${DOLLSIGN}http_host/ https://${DOLLSIGN}host:${DOLLSIGN}server_port/; } location /longpolling { - proxy_pass http://${ODOO_SERVICE}longpoll; + proxy_pass http://${SERVICE}longpoll; } }