Skip to content

Instantly share code, notes, and snippets.

@charlie-chiu
Created August 11, 2020 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlie-chiu/ce8cb0101548cc5a412068c475e598cd to your computer and use it in GitHub Desktop.
Save charlie-chiu/ce8cb0101548cc5a412068c475e598cd to your computer and use it in GitHub Desktop.
docker_vol2
version: '3.8'
services:
nginx:
# 直接拿 nginx official image 來使用
image: library/nginx:1.19-alpine
container_name: "charlie_nginx"
ports:
- 80:80
volumes:
- "./nginx.conf:/etc/nginx/conf.d/default.conf"
- "./app:/var/www/html"
php:
# PHP 常常要設定執行環境或其他 extensions ,另外 build image 使用
image: "charlie_php"
build: ./php
container_name: "charlie_php"
ports:
- 9000:9000
volumes:
- "./app:/var/www/html"
# 直接用 official image,可以省下很多工
FROM php:7.4.9-fpm-alpine
COPY php.ini $PHP_INI_DIR/conf.d/
# 安裝 php extensions 的神器,請務必一試!
# https://github.com/mlocati/docker-php-extension-installer
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
RUN install-php-extensions redis mysqli xdebug
<?php
//這裡放你的 php 程式,我習慣在建立環境時用 phpinfo() 來確認相關的 extensions 是不是正確安裝
echo "<h1>Charlie C</h1>";
phpinfo();
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php;
#把 script 轉給 php container 處理
location ~ \.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
}
date.timezone = "Asia/Taipei"
display_errors = 1
error_reporting = E_ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment