alpline 构建lnmp
alpline 构建lnmp
default.conf
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
root "/app/public";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log off;
sendfile on;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}
Dockerfile
3.11 版alpine,默认对应的php版本是7.3.22
FROM alpine:3.11
LABEL maintainer="gongxiaoliao@kailinjt.com"
COPY Shanghai /etc/localtime
ENV TIME_ZONE Asia/Shanghai
RUN echo "net.core.somaxconn = 65535" >> /etc/sysctl.conf && \
echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf && \
echo "Asia/Shanghai" > /etc/timezone
# 添加用户
RUN adduser www -H -D -s /sbin/nologin && \
adduser redis -H -D -s /sbin/nologin
# 安装nginx
RUN apk add nginx && \
sed -i '/user/s#nginx#www#' /etc/nginx/nginx.conf && \
mkdir -p /run/nginx && \
chown -R www.www /run/nginx
COPY default.conf /etc/nginx/conf.d/
# 安装php
RUN apk add php7 php7-fpm php7-pecl-apcu php7-bcmath php7-ctype php7-curl php7-dom php7-exif php7-fileinfo \
php7-gd php7-iconv php7-pecl-igbinary php7-intl php7-json php7-pecl-mcrypt php7-mysqli php7-pcntl php7-pdo \
php7-pdo_mysql php7-pdo_pgsql php7-phar php7-posix php7-pecl-redis php7-session php7-simplexml php7-tokenizer \
php7-xml php7-xsl php7-opcache php7-zip php7-xmlwriter php7-xmlreader php7-zmq && \
sed -i '/user/s#nobody#www#g' /etc/php7/php-fpm.d/www.conf && \
sed -i '/group/s#nobody#www#g' /etc/php7/php-fpm.d/www.conf && \
sed -i '/\;slowlog/s#\;##g' /etc/php7/php-fpm.d/www.conf
# 添加代码
COPY app /app
RUN chown -R www.www /app
RUN apk add redis
COPY redis.conf /etc/
WORKDIR /app
EXPOSE 80
# 安装守护进程
RUN apk add supervisor
COPY supervisor.conf /etc/supervisor/
COPY supervisor.nginx.conf /etc/supervisor/conf.d/
COPY supervisor.phpfpm.conf /etc/supervisor/conf.d/
COPY supervisor.redis.conf /etc/supervisor/conf.d/
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisor.conf"]
supervisor
# supervisor.conf
[unix_http_server] ; Web管理配置
file=/run/supervisord.sock ; socket文件路径
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
user=root ;
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///dev/shm/supervisor.sock ; use a unix:// URL for a unix socket
[include]
files = /etc/supervisor/conf.d/*.conf
# supervisor.nginx.conf
[program:nginx]
command=nginx -g "daemon off;"
autostart=true
autorestart=true
priority=10
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopsignal=QUIT
# supervisor.phpfpm.conf
[program:php-fpm]
command = php-fpm7 --force-stderr --nodaemonize
autostart=true
autorestart=true
priority=5
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopsignal=QUIT
# supervisor.redis.conf
[program:redis]
command=redis-server /etc/redis.conf
autostart=true
autorestart=true
priority=10
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopsignal=QUIT

浙公网安备 33010602011771号