update
This commit is contained in:
84
nginx-php/ADD/ccmd
Executable file
84
nginx-php/ADD/ccmd
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
##################################################
|
||||
# Mount dir #
|
||||
# - /etc/nginx/stream.d #
|
||||
# - /etc/nginx/http.d #
|
||||
# - /var/lib/nginx/html #
|
||||
# - /var/log/nginx #
|
||||
# - /var/log/php7 #
|
||||
##################################################
|
||||
|
||||
set -euo pipefail
|
||||
export LANG=en_US.UTF-8
|
||||
trap Quit EXIT
|
||||
|
||||
PIDS=
|
||||
GOT_SIGTERM=
|
||||
|
||||
function Print {
|
||||
local file=/dev/null
|
||||
[ '-f' = "$1" ] && file=$2 && shift && shift
|
||||
date +"[%F %T] $*" | tee -a $file
|
||||
}
|
||||
|
||||
function Quit {
|
||||
local running
|
||||
while running= ; do
|
||||
pkill -f php-fpm7 && running=1 && Print killing php-fpm7 ...
|
||||
pkill -f sleep && running=1 && Print killing sleep ...
|
||||
pkill -f nginx && running=1 && Print killing nginx ...
|
||||
[ -z "$running" ] && break
|
||||
sleep 1
|
||||
done
|
||||
Print Container stopped.
|
||||
test -n "$GOT_SIGTERM"
|
||||
}
|
||||
|
||||
function SideCar {
|
||||
local day= last_day=$(date +%d)
|
||||
local md5= last_md5=$(find /etc/nginx/ -type f -name "*.conf" \
|
||||
| xargs -I ^ md5sum ^ | md5sum)
|
||||
while sleep 10; do
|
||||
day=$(date +%d) \
|
||||
&& [ "$day" != "$last_day" ] \
|
||||
&& last_day=$day \
|
||||
&& find /var/log/nginx/ -type f -name "*.log" \
|
||||
| xargs -I ^ mv -f ^ ^.$(date +%F -d yesterday) \
|
||||
&& nginx -s reopen
|
||||
md5=$(find /etc/nginx/ -type f -name "*.conf" | xargs -I ^ md5sum ^ \
|
||||
| md5sum) \
|
||||
&& [ "$md5" != "$last_md5" ] \
|
||||
&& last_md5=$md5 \
|
||||
&& nginx -tq \
|
||||
&& Print Reload nginx conf ... \
|
||||
&& nginx -s reload
|
||||
done
|
||||
}
|
||||
|
||||
function StartProc {
|
||||
Print Start php ...
|
||||
php-fpm7 -F -y /etc/php7/php-fpm.conf &
|
||||
PIDS="$PIDS $!"
|
||||
Print Start nginx ...
|
||||
nginx -g 'daemon off;pid /run/nginx/nginx.pid;' &
|
||||
PIDS="$PIDS $!"
|
||||
Print Start nginx sidecar ...
|
||||
SideCar &
|
||||
PIDS="$PIDS $!"
|
||||
}
|
||||
|
||||
function Main {
|
||||
local pid=
|
||||
StartProc
|
||||
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
|
||||
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
|
||||
for pid in $PIDS; do
|
||||
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Start here
|
||||
Main
|
||||
|
17
nginx-php/Demo/SingleNode/README.md
Normal file
17
nginx-php/Demo/SingleNode/README.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# 部署单节点 nginx-php
|
||||
|
||||
- 根据实际环境修改
|
||||
- docker-compose.yml
|
||||
- nginx/http.d/80.conf
|
||||
|
||||
- 创建目录
|
||||
```
|
||||
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
|
||||
```
|
||||
|
||||
- 上传可能需要的前端文件到 nginx/html/ 下
|
||||
- 启动
|
||||
```
|
||||
docker-compose up -d
|
||||
```
|
||||
|
25
nginx-php/Demo/SingleNode/docker-compose.yml
Normal file
25
nginx-php/Demo/SingleNode/docker-compose.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
version: "3.7"
|
||||
|
||||
services:
|
||||
nginx-php:
|
||||
image: harbor.colben.cn/general/nginx-php
|
||||
container_name: nginx-php
|
||||
restart: "on-failure"
|
||||
stop_grace_period: 5m
|
||||
privileged: true
|
||||
ports:
|
||||
- 80:80
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ./nginx/html
|
||||
target: /var/lib/nginx/html
|
||||
- type: bind
|
||||
source: ./nginx/http.d
|
||||
target: /etc/nginx/http.d
|
||||
- type: bind
|
||||
source: ./nginx/log
|
||||
target: /var/log/nginx
|
||||
- type: bind
|
||||
source: ./php7/log
|
||||
target: /var/log/php7
|
||||
|
25
nginx-php/Demo/SingleNode/nginx/http.d/80.conf
Normal file
25
nginx-php/Demo/SingleNode/nginx/http.d/80.conf
Normal file
@@ -0,0 +1,25 @@
|
||||
server {
|
||||
listen 80;
|
||||
location /xxxx/ {}
|
||||
location ~ ^/xxxx/.+\.php$ {
|
||||
client_max_body_size 1024m;
|
||||
client_body_buffer_size 1024m;
|
||||
fastcgi_buffer_size 256k;
|
||||
fastcgi_buffers 8 256k;
|
||||
fastcgi_busy_buffers_size 512k;
|
||||
fastcgi_temp_file_write_size 512k;
|
||||
expires -1s;
|
||||
include fastcgi_params;
|
||||
try_files $uri =404;
|
||||
fastcgi_pass unix:/var/lib/php7/phpfpm.sock;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
break;
|
||||
}
|
||||
location / {
|
||||
return 403;
|
||||
}
|
||||
}
|
||||
|
25
nginx-php/Dockerfile
Normal file
25
nginx-php/Dockerfile
Normal file
@@ -0,0 +1,25 @@
|
||||
ARG ARCH
|
||||
FROM harbor.colben.cn/general/nginx$ARCH
|
||||
MAINTAINER Colben colbenlee@gmail.com
|
||||
ADD --chown=root:root /ADD/ /opt/
|
||||
RUN apk update \
|
||||
&& apk add --no-cache php7 php7-common php7-iconv php7-json php7-gd php7-curl php7-xml \
|
||||
php7-mysqli php7-imap php7-cgi fcgi php7-pdo php7-pdo_mysql php7-soap php7-xmlrpc \
|
||||
php7-posix php7-mcrypt php7-gettext php7-ldap php7-ctype php7-dom php7-fpm \
|
||||
php7-mbstring php7-mysqlnd php7-bcmath php7-session php7-openssl php7-opcache \
|
||||
&& sed -i -e '/^;* *max_execution_time *=/cmax_execution_time = 300' \
|
||||
-e '/^;* *memory_limit *=/cmemory_limit = 1024M' \
|
||||
-e '/^;* *post_max_size *=/cpost_max_size = 1024M' \
|
||||
-e '/^;* *upload_max_filesize *=/cupload_max_filesize = 1024M' \
|
||||
-e '/^;* *max_input_time *=/cmax_input_time = 300' \
|
||||
-e '/^;* *max_input_vars *=/cmax_input_vars = 10000' \
|
||||
-e '/^;* *date.timezone *=/cdate.timezone = PRC' \
|
||||
-e '/^;* *pdo_mysql.default_socket *=/cpdo_mysql.default_socket = /run/mysqld/mysqld.sock' \
|
||||
-e '/^;* *mysqli.default_socket *=/cmysqli.default_socket = /run/mysqld/mysqld.sock' \
|
||||
/etc/php7/php.ini \
|
||||
&& sed -i -e '/^;* *listen *=/clisten = /var/lib/php7/phpfpm.sock' \
|
||||
-e '/^;* *listen.mode *=/clisten.mode = 0666' \
|
||||
/etc/php7/php-fpm.d/www.conf \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
CMD ["/opt/ccmd"]
|
||||
|
26
nginx-php/Dockerfile-3.9
Normal file
26
nginx-php/Dockerfile-3.9
Normal file
@@ -0,0 +1,26 @@
|
||||
FROM alpine:3.9
|
||||
MAINTAINER Colben colbenlee@gmail.com
|
||||
ADD --chown=root:root /ADD/ /opt/
|
||||
ENV PS1='\[\e[33;1;1m\][\[\e[0m\]\[\e[35;1m\]\u\[\e[0m\]\[\e[33;1;1m\]@\[\e[0m\]\[\e[31;1;1m\]docker\[\e[0m\]\[\e[32;1;1m\](\h)\[\e[0m\]\[\e[33;1;1m\]:\[\e[0m\]\[\e[32m\]\w\[\e[0m\]\[\e[33;1;1m\]]\[\e[0m\]\[\e[36m\]\$\[\e[0m\] '
|
||||
ENV PS2='\[\e[36m\]>\[\e[0m\] '
|
||||
ENV LANG=en_US.UTF-8
|
||||
RUN ln -s /opt/localtime /etc/localtime \
|
||||
&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
|
||||
&& apk update \
|
||||
&& apk add --no-cache bash curl coreutils nginx php7 php7-common php7-session php7-openssl php7-iconv php7-json php7-gd php7-curl php7-xml php7-mysqli php7-imap php7-cgi fcgi php7-pdo php7-pdo_mysql php7-soap php7-xmlrpc php7-posix php7-mcrypt php7-gettext php7-ldap php7-ctype php7-dom php7-fpm php7-mbstring php7-mysqlnd php7-bcmath \
|
||||
&& sed -i -e '/^;* *max_execution_time *=/cmax_execution_time = 300' \
|
||||
-e '/^;* *memory_limit *=/cmemory_limit = 1024M' \
|
||||
-e '/^;* *post_max_size *=/cpost_max_size = 1024M' \
|
||||
-e '/^;* *upload_max_filesize *=/cupload_max_filesize = 1024M' \
|
||||
-e '/^;* *max_input_time *=/cmax_input_time = 300' \
|
||||
-e '/^;* *max_input_vars *=/cmax_input_vars = 10000' \
|
||||
-e '/^;* *date.timezone *=/cdate.timezone = PRC' \
|
||||
/etc/php7/php.ini \
|
||||
&& sed -i -e '/^;* *listen *=/clisten = /var/lib/php7/phpfpm.sock' \
|
||||
-e '/^;* *listen.mode *=/clisten.mode = 0666' \
|
||||
/etc/php7/php-fpm.d/www.conf \
|
||||
&& mkdir /run/nginx \
|
||||
&& chown nginx.nginx /run/nginx \
|
||||
&& rm -rf /var/cache/apk/* /etc/nginx/conf.d/*
|
||||
CMD ["/opt/ccmd"]
|
||||
|
17
nginx-php/README.md
Normal file
17
nginx-php/README.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# 构建 nginx-php 镜像
|
||||
|
||||
## 定制
|
||||
- 安装 nginx 和 php7
|
||||
- 固定一些常用配置
|
||||
- 每 10 秒扫描一次配置文件,有变更会立即 reload
|
||||
|
||||
## 外挂目录和文件
|
||||
- /etc/nginx/stream.d: nginx stream 配置文件
|
||||
- /etc/nginx/http.d: nginx http 配置文件
|
||||
- /var/lib/nginx/html: nginx 前端文件存放目录
|
||||
- /var/log/nginx: nginx 日志目录
|
||||
- /var/log/php7: php7 日志目录
|
||||
|
||||
## 案例
|
||||
- [Demo/SingleNode/](Demo/SingleNode/): 部署 nginx-php
|
||||
|
67
nginx-php/nginx-php.sh
Executable file
67
nginx-php/nginx-php.sh
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
#=========================================
|
||||
# Author : colben
|
||||
#=========================================
|
||||
|
||||
set -euo pipefail
|
||||
export LANG=en_US.UTF-8
|
||||
trap Quit EXIT
|
||||
|
||||
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
|
||||
ROOT_DIR="$(cd $(dirname $0) && pwd)"
|
||||
IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:latest"
|
||||
|
||||
if [ -t 0 ]; then
|
||||
function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; }
|
||||
function Warn { echo -e "\033[36;1m$(date +'[%F %T]')\033[33;1m $*\033[0m"; }
|
||||
function Error { echo -e "\033[36;1m$(date +'[%F %T]')\033[31;1m $*\033[0m"; exit 1; }
|
||||
else
|
||||
function Print { echo -e "$(date +'[%F %T INFO]') $*"; }
|
||||
function Warn { echo -e "$(date +'[%F %T WARN]') $*"; }
|
||||
function Error { echo -e "$(date +'[%F %T ERROR]') $*"; exit 1; }
|
||||
fi
|
||||
|
||||
function Quit {
|
||||
local exitCode=$?
|
||||
[ 0 -ne $exitCode ] && Error Failed to build or push image!
|
||||
[ -z "${END:-}" ] && echo && Error Interrupted manually!
|
||||
Print Succeeded to build and push image.
|
||||
}
|
||||
|
||||
function YesOrNo {
|
||||
Warn $*
|
||||
local sw=
|
||||
while :; do
|
||||
read -p '(Yes/No/Quit) ' -n1 sw
|
||||
[[ "$sw" =~ ^Y|y$ ]] && echo && return 0
|
||||
[[ "$sw" =~ ^N|n$ ]] && echo && return 1
|
||||
[[ "$sw" =~ ^Q|q$ ]] && echo && exit 0
|
||||
[ -n "$sw" ] && echo
|
||||
done
|
||||
}
|
||||
|
||||
function Update {
|
||||
:
|
||||
}
|
||||
|
||||
function Build {
|
||||
local yn
|
||||
cd $ROOT_DIR
|
||||
docker images --format='{{.Repository}}:{{.Tag}}' | grep "^$IMAGE$" \
|
||||
&& Warn Removing image $IMAGE ... \
|
||||
&& docker rmi $IMAGE
|
||||
Warn Building image: $IMAGE ...
|
||||
docker build --force-rm --build-arg ARCH="$ARCH" -t $IMAGE .
|
||||
YesOrNo Push image: $IMAGE? && docker push $IMAGE
|
||||
}
|
||||
|
||||
function Main {
|
||||
Update
|
||||
Build
|
||||
END=1
|
||||
}
|
||||
|
||||
# Start here
|
||||
Main
|
||||
|
Reference in New Issue
Block a user