Skip to content

Commit

Permalink
Try
Browse files Browse the repository at this point in the history
  • Loading branch information
DolgovAleksandr committed Sep 17, 2023
1 parent 0422267 commit 62f1bbb
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 51 deletions.
48 changes: 39 additions & 9 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -28,8 +55,9 @@ services:
build:
context: ./..
dockerfile: docker/fpm/Dockerfile
image: myapp/php
container_name: app1
ports:
- ":9000"
volumes:
- ../src:/app
networks:
Expand All @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions docker/nginx-child/Dockerfile
Original file line number Diff line number Diff line change
@@ -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;"]
Original file line number Diff line number Diff line change
@@ -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;
}
}
File renamed without changes.
20 changes: 20 additions & 0 deletions docker/nginx-root/application.local.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 62f1bbb

Please sign in to comment.