소스 검색

make the PHP_UPSTREAM config for NGINX and Apache identical

Mahmoud Zalt 7 년 전
부모
커밋
5c0b8316b1
4개의 변경된 파일19개의 추가작업 그리고 11개의 파일을 삭제
  1. 3 2
      apache2/Dockerfile
  2. 5 3
      docker-compose.yml
  3. 4 2
      env-example
  4. 7 4
      nginx/Dockerfile

+ 3 - 2
apache2/Dockerfile

@@ -2,9 +2,10 @@ FROM webdevops/apache:ubuntu-16.04
 
 MAINTAINER Eric Pfeiffer <computerfr33k@users.noreply.github.com>
 
-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/
 

+ 5 - 3
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:

+ 4 - 2
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 ##############################################################################################################
 

+ 7 - 4
nginx/Dockerfile

@@ -4,7 +4,8 @@ MAINTAINER Mahmoud Zalt <mahmoud@zalt.me>
 
 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"]