Skip to content

Commit

Permalink
Homework 4 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SlavaMakhov committed Dec 21, 2024
1 parent a794c6a commit 7371738
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 36 deletions.
21 changes: 21 additions & 0 deletions app/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

/**
* @param $class_name
*
* @return false|void
*/
function autoloader($class_name)
{
$file = __DIR__ . '/' . implode('/', explode("\\", $class_name)) . '.php';

if (!file_exists($file)) {
return false;
}

include $file;
}

spl_autoload_register('autoloader');
8 changes: 6 additions & 2 deletions app/index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

declare(strict_types=1);
error_reporting(E_ALL);
mb_internal_encoding("UTF-8");

echo "Привет, otus!<br>" . date("Y-m-d H:i:s") . "<br><br>";
require 'autoload.php';

echo "Запрос обработал контейнер: " . $_SERVER['HOSTNAME'];
echo "Привет, Otus!<br>".date("Y-m-d H:i:s")."<br><br>";

echo "Запрос обработал контейнер: " . $_SERVER['HOSTNAME'];
57 changes: 33 additions & 24 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
version: "3"
version: '3'

services:
nginx:
build:
context: ./docker/nginx
dockerfile: Dockerfile
image: otus2024-hw4/nginx
container_name: otus2024-hw4-nginx
ports:
- "80:80"
volumes:
- ./app:/var/www/otus2024
networks:
- otus2024-network

app1:
build:
context: ./docker/fpm
dockerfile: Dockerfile
image: otus2024-hw4/php
image: balance/php
container_name: app1
restart: unless-stopped
volumes:
- ./app:/var/www/otus2024
networks:
Expand All @@ -17,39 +29,36 @@ services:
build:
context: ./docker/fpm
dockerfile: Dockerfile
image: otus2024-hw4/php
image: balance/php
container_name: app2
restart: unless-stopped
volumes:
- ./app:/var/www/otus2024
networks:
- otus2024-network

redis:
image: redis:6.0.7
container_name: redisApp
restart: always
volumes:
- ./redis:/data/redis
# ports:
# - "6379:6379"
networks:
- otus2024-network

nginx:
app3:
build:
context: ./docker/nginx
context: ./docker/fpm
dockerfile: Dockerfile
image: otus2024-hw4/nginx
container_name: otus2024-hw4-nginx
restart: unless-stopped
ports:
- "80:80"
image: balance/php
container_name: app3
volumes:
- ./app:/var/www/otus2024
networks:
- otus2024-network

networks:
otus2024-network:
driver: bridge
driver: bridge


# redis:
# image: redis:6.0.7
# container_name: redisApp
# restart: always
# volumes:
# - ./redis:/data/redis
# # ports:
# # - "6379:6379"
# networks:
# - otus2024-network
2 changes: 1 addition & 1 deletion docker/fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ WORKDIR /var/www

VOLUME /var/www

EXPOSE 9000
#EXPOSE 9000

CMD ["php-fpm"]
4 changes: 3 additions & 1 deletion docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM nginx
FROM nginx:latest

COPY ./conf.d/mysite.local.conf /etc/nginx/conf.d/mysite.local.conf

WORKDIR /var/www

VOLUME /var/www

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
25 changes: 17 additions & 8 deletions docker/nginx/conf.d/mysite.local.conf
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
upstream php-fpm-backend {
least_conn;
server app1:9000;
server app2:9000;
server app3:9000;
}

server {
# указываем 80 порт для соединения
listen 80;

# нужно указать, какому доменному имени принадлежит наш конфиг
server_name mysite.local;

# задаём корневую директорию
root /var/www/otus2024;

# стартовый файл
index index.php index.html;

error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;

# при обращении к статическим файлам логи не нужны, равно как и обращение к fpm
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;
gzip_static on;
}

# и наконец правило обращения к php-fpm
location ~* .php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass app1:9000;
fastcgi_pass php-fpm-backend;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}

0 comments on commit 7371738

Please sign in to comment.