From 62f1bbbb3bf6bf59ca8fa7f74b2c742b1152a08c Mon Sep 17 00:00:00 2001 From: adolgov99 Date: Mon, 18 Sep 2023 01:23:05 +0700 Subject: [PATCH] Try --- docker/docker-compose.yaml | 48 +++++++++--- docker/nginx-child/Dockerfile | 11 +++ .../application.local.conf | 73 ++++++++----------- docker/{nginx => nginx-root}/Dockerfile | 0 docker/nginx-root/application.local.conf | 20 +++++ 5 files changed, 101 insertions(+), 51 deletions(-) create mode 100644 docker/nginx-child/Dockerfile rename docker/{nginx => nginx-child}/application.local.conf (60%) rename docker/{nginx => nginx-root}/Dockerfile (100%) create mode 100644 docker/nginx-root/application.local.conf diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 8aa5cbf7d..854bb027a 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -1,16 +1,43 @@ version: '3' services: - nginx: + nginx-root: build: - context: ./nginx + context: ./nginx-root dockerfile: Dockerfile - image: myapp/nginx - container_name: webserver + container_name: nginx-root ports: - "80:80" + networks: + - app-network + + nginx-child-1: + build: + context: ./nginx-child + dockerfile: Dockerfile + container_name: nginx-child-1 + volumes: + - ../src:/app + networks: + - app-network + + nginx-child-2: + build: + context: ./nginx-child + dockerfile: Dockerfile + container_name: nginx-child-2 volumes: - - ../src:/app + - ../src:/app + networks: + - app-network + + nginx-child-3: + build: + context: ./nginx-child + dockerfile: Dockerfile + container_name: nginx-child-3 + volumes: + - ../src:/app networks: - app-network @@ -28,8 +55,9 @@ services: build: context: ./.. dockerfile: docker/fpm/Dockerfile - image: myapp/php container_name: app1 + ports: + - ":9000" volumes: - ../src:/app networks: @@ -40,20 +68,22 @@ services: build: context: ./.. dockerfile: docker/fpm/Dockerfile - image: myapp/php container_name: app2 + ports: + - ":9000" volumes: - ../src:/app networks: - app-network - # second php-fpm + # third php-fpm app3: build: context: ./.. dockerfile: docker/fpm/Dockerfile - image: myapp/php container_name: app3 + ports: + - ":9000" volumes: - ../src:/app networks: diff --git a/docker/nginx-child/Dockerfile b/docker/nginx-child/Dockerfile new file mode 100644 index 000000000..91ea57210 --- /dev/null +++ b/docker/nginx-child/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx + +COPY ./application.local.conf /etc/nginx/conf.d/application.local.conf + +WORKDIR /app + +VOLUME /app + +EXPOSE 8871 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/nginx/application.local.conf b/docker/nginx-child/application.local.conf similarity index 60% rename from docker/nginx/application.local.conf rename to docker/nginx-child/application.local.conf index f35cf9985..cc4ef0e3b 100644 --- a/docker/nginx/application.local.conf +++ b/docker/nginx-child/application.local.conf @@ -1,42 +1,31 @@ -upstream php-fpm-backend { - least_conn; - server app1:9000; - server app2:9000; - server app3:9000; -} - -server { - # указываем 80 порт для соединения - listen 80; - # нужно указать, какому доменному имени принадлежит наш конфиг - server_name application.local; - - # задаём корневую директорию - root /app; - - # стартовый файл - index index.php index.html; - - # при обращении к статическим файлам логи не нужны, равно как и обращение к fpm - # http://application.local/static/some.png - location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ { - access_log off; - expires max; - } - - # помним про единую точку доступа - # все запросы заворачиваются в корневую директорию root на index.php - location / { - try_files $uri $uri/ /index.php?$query_string; - } - - # и наконец правило обращения к php-fpm - location ~* .php$ { - try_files $uri = 404; - fastcgi_split_path_info ^(.+.php)(/.+)$; - fastcgi_pass php-fpm-backend; - fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - include fastcgi_params; - } -} +upstream backend { + server app1:9000; + server app2:9000; + server app3:9000; +} + +server { + # указываем 80 порт для соединения + listen 8871; + # нужно указать, какому доменному имени принадлежит наш конфиг + + # задаём корневую директорию + root /app; + + # стартовый файл + index index.php index.html; + + # помним про единую точку доступа + # все запросы заворачиваются в корневую директорию root на index.php + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + # и наконец правило обращения к php-fpm + location ~* .php$ { + fastcgi_pass backend; + + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } +} diff --git a/docker/nginx/Dockerfile b/docker/nginx-root/Dockerfile similarity index 100% rename from docker/nginx/Dockerfile rename to docker/nginx-root/Dockerfile diff --git a/docker/nginx-root/application.local.conf b/docker/nginx-root/application.local.conf new file mode 100644 index 000000000..88512a136 --- /dev/null +++ b/docker/nginx-root/application.local.conf @@ -0,0 +1,20 @@ +upstream nginx-balancer{ + server nginx-child-1:8871; + server nginx-child-2:8871; + server nginx-child-3:8871; +} + +server { + listen 80; + server_name application.local; + + location / { + proxy_pass http://nginx-balancer; + proxy_set_header Host $http_host; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Scheme $scheme; + } +}