-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SlavaMakhov
committed
Dec 21, 2024
1 parent
a794c6a
commit 7371738
Showing
6 changed files
with
81 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,6 @@ WORKDIR /var/www | |
|
||
VOLUME /var/www | ||
|
||
EXPOSE 9000 | ||
#EXPOSE 9000 | ||
|
||
CMD ["php-fpm"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |