From 60cd02b890bedd9d9d8521e329f50e5ef797dadf Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 3 Jul 2024 09:28:35 +0800 Subject: [PATCH] update php docker compose --- .gitignore | 1 + dockerfiles/php/docker-compose.yml | 16 ++++--- dockerfiles/php/{src => }/index.html | 0 dockerfiles/php/{src => }/index.php | 0 .../php/{ => nginx}/conf.d/default.conf | 0 dockerfiles/php/nginx/conf.d/tp.conf | 48 +++++++++++++++++++ dockerfiles/php/{ => nginx}/nginx.conf | 3 -- 7 files changed, 59 insertions(+), 9 deletions(-) rename dockerfiles/php/{src => }/index.html (100%) rename dockerfiles/php/{src => }/index.php (100%) rename dockerfiles/php/{ => nginx}/conf.d/default.conf (100%) create mode 100644 dockerfiles/php/nginx/conf.d/tp.conf rename dockerfiles/php/{ => nginx}/nginx.conf (99%) diff --git a/.gitignore b/.gitignore index 16a0c8a..51b25a1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ **/*/.DS_Store lazygit/state.yml tmux/plugins +**/*/mysql diff --git a/dockerfiles/php/docker-compose.yml b/dockerfiles/php/docker-compose.yml index 657d20a..f52a339 100644 --- a/dockerfiles/php/docker-compose.yml +++ b/dockerfiles/php/docker-compose.yml @@ -1,14 +1,12 @@ -version: "3.9" - services: web: image: nginx:alpine ports: - "4000:80" volumes: - - ./src:/var/www/html - - ./conf.d/:/etc/nginx/conf.d/ - - ./nginx.conf:/etc/nginx/nginx.conf + - .:/var/www/html + - ./nginx/conf.d/:/etc/nginx/conf.d/ + - ./nginx/nginx.conf:/etc/nginx/nginx.conf links: - php-fpm @@ -17,8 +15,14 @@ services: platform: linux/amd64 environment: MYSQL_ROOT_PASSWORD: qwer1234 + volumes: + - ./mysql:/var/lib/mysql + deploy: + resources: + limits: + memory: 8G php-fpm: image: php:7-fpm-alpine volumes: - - ./src:/var/www/html + - .:/var/www/html diff --git a/dockerfiles/php/src/index.html b/dockerfiles/php/index.html similarity index 100% rename from dockerfiles/php/src/index.html rename to dockerfiles/php/index.html diff --git a/dockerfiles/php/src/index.php b/dockerfiles/php/index.php similarity index 100% rename from dockerfiles/php/src/index.php rename to dockerfiles/php/index.php diff --git a/dockerfiles/php/conf.d/default.conf b/dockerfiles/php/nginx/conf.d/default.conf similarity index 100% rename from dockerfiles/php/conf.d/default.conf rename to dockerfiles/php/nginx/conf.d/default.conf diff --git a/dockerfiles/php/nginx/conf.d/tp.conf b/dockerfiles/php/nginx/conf.d/tp.conf new file mode 100644 index 0000000..d3b05f4 --- /dev/null +++ b/dockerfiles/php/nginx/conf.d/tp.conf @@ -0,0 +1,48 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + + #access_log /var/log/nginx/host.access.log main; + + root /var/www/html/public; + index index.php index.html; + + #error_page 404 /404.html; + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass php-fpm:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } + location / { + if (!-e $request_filename) { + rewrite ^(.*)$ /index.php?s=/$1 last; + } + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +} + diff --git a/dockerfiles/php/nginx.conf b/dockerfiles/php/nginx/nginx.conf similarity index 99% rename from dockerfiles/php/nginx.conf rename to dockerfiles/php/nginx/nginx.conf index 2987db1..7a33040 100644 --- a/dockerfiles/php/nginx.conf +++ b/dockerfiles/php/nginx/nginx.conf @@ -1,16 +1,13 @@ - user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; - events { worker_connections 1024; } - http { include /etc/nginx/mime.types; default_type application/octet-stream;