From 5c0b8316b1765a4104a5d81226b538b9732d50dc Mon Sep 17 00:00:00 2001 From: Mahmoud Zalt Date: Fri, 4 Aug 2017 00:50:20 +0300 Subject: [PATCH] make the PHP_UPSTREAM config for NGINX and Apache identical --- apache2/Dockerfile | 5 +++-- docker-compose.yml | 8 +++++--- env-example | 6 ++++-- nginx/Dockerfile | 11 +++++++---- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/apache2/Dockerfile b/apache2/Dockerfile index 9d4d9a9a..afbb7c2b 100644 --- a/apache2/Dockerfile +++ b/apache2/Dockerfile @@ -2,9 +2,10 @@ FROM webdevops/apache:ubuntu-16.04 MAINTAINER Eric Pfeiffer -ARG PHP_SOCKET=php-fpm:9000 +ARG PHP_UPSTREAM_CONTAINER=php-fpm +ARG PHP_UPSTREAM_PORT=9000 -ENV WEB_PHP_SOCKET=$PHP_SOCKET +ENV WEB_PHP_SOCKET=${PHP_UPSTREAM_CONTAINER}:${PHP_UPSTREAM_PORT} ENV WEB_DOCUMENT_ROOT=/var/www/public/ diff --git a/docker-compose.yml b/docker-compose.yml index 45049959..b0c9cb42 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -107,13 +107,14 @@ services: networks: - backend -### Nginx Server Container ################################## +### NGINX Server Container ################################## nginx: build: context: ./nginx args: - - PHP_UPSTREAM=php-fpm + - PHP_UPSTREAM_CONTAINER=${NGINX_PHP_UPSTREAM_CONTAINER} + - PHP_UPSTREAM_PORT=${NGINX_PHP_UPSTREAM_PORT} volumes_from: - applications volumes: @@ -146,7 +147,8 @@ services: build: context: ./apache2 args: - - PHP_SOCKET=${PHP_SOCKET} + - PHP_UPSTREAM_CONTAINER=${APACHE_PHP_UPSTREAM_CONTAINER} + - PHP_UPSTREAM_PORT=${APACHE_PHP_UPSTREAM_PORT} volumes_from: - applications volumes: diff --git a/env-example b/env-example index 184b34f6..a749ca42 100644 --- a/env-example +++ b/env-example @@ -80,15 +80,17 @@ NGINX_HOST_HTTP_PORT=80 NGINX_HOST_HTTPS_PORT=443 NGINX_HOST_LOG_PATH=./logs/nginx/ NGINX_SITES_PATH=./nginx/sites/ +NGINX_PHP_UPSTREAM_CONTAINER=php-fpm +NGINX_PHP_UPSTREAM_PORT=9000 ### APACHE ############################################################################################################# APACHE_HOST_HTTP_PORT=80 APACHE_HOST_HTTPS_PORT=443 -APACHE2_PHP_SOCKET=php-fpm:9000 APACHE_HOST_LOG_PATH=./logs/apache2 APACHE_SITES_PATH=./apache2/sites -PHP_SOCKET=php-fpm:9000 +APACHE_PHP_UPSTREAM_CONTAINER=php-fpm +APACHE_PHP_UPSTREAM_PORT=9000 ### MYSQL ############################################################################################################## diff --git a/nginx/Dockerfile b/nginx/Dockerfile index e23be3d5..77f4abdd 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -4,7 +4,8 @@ MAINTAINER Mahmoud Zalt ADD nginx.conf /etc/nginx/ -ARG PHP_UPSTREAM=php-fpm +ARG PHP_UPSTREAM_CONTAINER=php-fpm +ARG PHP_UPSTREAM_PORT=9000 # fix a problem--#397, change application source from dl-cdn.alpinelinux.org to aliyun source. RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories @@ -12,9 +13,11 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories RUN apk update \ && apk upgrade \ && apk add --no-cache bash \ - && adduser -D -H -u 1000 -s /bin/bash www-data \ - && rm /etc/nginx/conf.d/default.conf \ - && echo "upstream php-upstream { server ${PHP_UPSTREAM}:9000; }" > /etc/nginx/conf.d/upstream.conf + && adduser -D -H -u 1000 -s /bin/bash www-data + +# Set upstream conf and remove the default conf +RUN echo "upstream php-upstream { server ${PHP_UPSTREAM_CONTAINER}:${PHP_UPSTREAM_PORT}; }" > /etc/nginx/conf.d/upstream.conf \ + && rm /etc/nginx/conf.d/default.conf CMD ["nginx"]