前言


在以往的容器环境部署中 运行环境 我们通常把 类似 apache nginx php 等 打包在一个镜像中 起一个容器。 这样做的好处是 方便 简单。 不便的地方是 如果PHP 需要扩展新的 相关组件就麻烦了。例如笔者之前用的 apache+php 组合在一个镜像中 需要添加 php-redis 扩展,就很麻烦 因为这个扩展需要重新编译(常见的扩展只需要添加 或者安装 )。 如果编译的化 时间久依赖多 问题多。

并且 nginx php-fpm 相关软件都是 独立开源软件 官方并不提供完整组合 套件 ; 放在一个容器中 拼凑起来 对新人 不太方便; 今天通过 摸索 可以实现 通过组合来搭建 php 运行环境。

php

php 官方镜像构建

#使用国内网易镜像可以加快构建速度
FROM hub.c.163.com/library/php:fpm-alpine
#FROM php:fpm-alpine MAINTAINER Alu alu@xdreport.com #国内repo源,让本地构建速度更快。
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories #安装GD依赖库
RUN apk add --no-cache --virtual .build-deps \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libmcrypt-dev #添加php源码中的扩展,添加gd,mysqli,pdo-mysql,opcache,gettext,mcrypt等扩展
RUN set -ex \
&& docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/freetype2/freetype \
--with-jpeg-dir=/usr/include \
--with-png-dir=/usr/include \
&& docker-php-ext-install gd bcmath zip opcache iconv mcrypt pdo pdo_mysql mysqli #redis属于pecl扩展,需要使用pecl命令来安装,同时需要添加依赖的库
RUN apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS \
&& pecl install redis-3.1.2 \
&& docker-php-ext-enable redis \
&& apk del .phpize-deps

安装redis 扩展

curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/3.1.3.tar.gz
tar xfz /tmp/redis.tar.gz
rm -r /tmp/redis.tar.gz
mkdir -p /usr/src/php/ext
mv phpredis-3.1.3 /usr/src/php/ext/redis
docker-php-ext-install redis
nginx

# 习惯nginx alpine 这个版本 因为小 7M
docker pull nginx:alpine
nginx 配置
  • /etc/nginx/conf.d/default.conf
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
#root /usr/share/nginx/html;
root /var/www/html; # `这个配置 用 php-fmp 镜像 容器中的 PHP 根目录地址 切记这个不是 nginx web根目录地址 这个问题折腾了我好久`
fastcgi_pass phpfpm:9000; # 修改这个地址为 phpfpm 容器的名称 我的容器名称就是 phpfmp
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

参考完整 default.conf

server {
listen 80;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
client_max_body_size 4080m;
send_timeout 6000;
fastcgi_connect_timeout 6000;
fastcgi_send_timeout 6000;
fastcgi_read_timeout 6000; location / {
#try_files $uri $uri/ /index.php$uri?$query_string;
root /usr/share/nginx/html;
index index.html index.php index.htm;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
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
#
location ~ .+\.php($|/) {
root /var/www/html/public;
fastcgi_pass phpfmp:9000;
fastcgi_index index.php;
#加载Nginx默认"服务器环境变量"配置
include fastcgi.conf; #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量
set $fastcgi_script_name2 $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
set $fastcgi_script_name2 $1;
set $path_info $2;
}
fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

大文件配置参考

nginx的修改        /etc/nginx/conf.d/default.conf
send_timeout 60;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
client_max_body_size 30m; php的修改 /usr/local/etc/php/ 中的配置文件 复制 为php.ini
upload_max_filesize
post_max_size
max_input_time
max_execution_time php-fpm注意参数
request_terminate_timeout
request_slowlog_timeout
这两个参数如果设置过小的话会导致文件传输了一部分后连接关闭。
组合(rancher)
phpfpm:
tty: true
image: hub.03in.com:5002/ranmufei/phpalpine-redis:v1
volumes:
- /home/www/nginx4/html:/var/www/html
stdin_open: true
nginx4:
ports:
- 7575:80/tcp
tty: true
image: nginx:alpine
links:
- phpfpm:phpfmp
volumes:
- /home/www/nginx4/html:/usr/share/nginx/html
- /home/www/nginx4/conf/default.conf:/etc/nginx/conf.d/default.conf
- /home/www/nginx4/conf/nginx.conf:/etc/nginx/nginx.conf
stdin_open: true

docker nginx镜像+phpfpm 镜像 组合配置 搭建 PHP+nginx 环境的更多相关文章

  1. JBOSS安装与配置搭建本地项目环境(方便前端开发调式)

    JBOSS安装与配置搭建本地项目环境  什么是JBOSS? JBOSS是EJB的服务器,就像Tomcat是JSP服务器一样,就是服务器的一种. 环境搭建如下: 一:首先安装JDK,配置环境变量(PAT ...

  2. 珠联壁合地设天造|M1 Mac os(Apple Silicon)基于vscode(arm64)配置搭建Java开发环境(集成web框架Springboot)

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_194 也许有人从未听说过Python,但是不会有人没听说过Java,它作为一个拥有悠久历史的老牌编程语言,常年雄踞TIOBE编程语 ...

  3. [转]Nginx+mysql+php-fpm负载均衡配置实例

    转 : http://www.jbxue.com/article/7923.html 介绍一个nginx.mysql.php-fpm环境下配置负载均衡的例子,有需要的朋友,可以参考下. 系统环境如下: ...

  4. MyEclipse+PyDev配置搭建Python开发环境

    打开help-> install from catalog 输入pydev查找并安装pydev 根据提示进行安装,安装完后重启myeclipse

  5. ubuntu下搭建nginx+mysql+php-fpm站点

    概述 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器.  nginx的优势在于能以低内存高 ...

  6. nginx调用php-fpm出错解决方法和nginx配置详解

    装完了nginx和php-5.5,配置好了nginx调用php后,就开始启动php-fpm. 使用下面的命令 复制代码 代码如下: /usr/local/php/sbin/php-fpm 就可以启动了 ...

  7. nginx和php-fpm调用方式

    一.背景: 在开发中碰到一个问题,项目以nginx+php-fpm形式访问交互,结果访问项目时报错如下图:   二.分析: 提示很明确嘛,去看error.log(在nginx.conf或者vhost里 ...

  8. LNMP小项目搭建,Centos7.6环境搭建Linux+nginx+mysql+php,wordpress个人博客的搭建(完整搭建步骤)

    一.LNMP搭建,基于nginx服务器搭建wordpress个人博客 准备环境:centos7.6环境下web服务器(nginx+php):主机名:web01,ip:192.168.248.172my ...

  9. 把www.domain.com均衡到本机不同的端口 反向代理 隐藏端口 Nginx做非80端口转发 搭建nginx反向代理用做内网域名转发 location 规则

    负载均衡-Nginx中文文档 http://www.nginx.cn/doc/example/loadbanlance.html 负载均衡 一个简单的负载均衡的示例,把www.domain.com均衡 ...

随机推荐

  1. 【cookie】【浏览器】各大浏览器对cookie的限制

  2. wordpress配置SMTP服务发送邮件(qq邮箱)

    wordpress有一个注册功能,填了用户名和邮箱后,会收到一封邮件,邮件里有一个链接,点击该链接可以获得密码和修改密码.但是,最开始,你会发现,等半天都没有收到邮件,再等到猴年马月也不会收到. 但是 ...

  3. boot_mem分配器

    #define alloc_bootmem_low_pages(x) \ __alloc_bootmem_low(x, PAGE_SIZE, ) void * __init __alloc_bootm ...

  4. linux下C++的多线程编程

    1. 引言 线程(thread)技术早在60年代就被提出,但真正应用多线程到操作系统中去,是在80年代中期,solaris是这方面的佼佼者.传统的Unix也支持线程的概念,但是在一个进程(proces ...

  5. POJ-1061 青蛙的约会 (扩展欧几里得)

    [题目描述] 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事情,既没有 ...

  6. Struts2之初体验

    Struts21.了解Struts2 请求调度框架Struts2是一个MVC框架Struts2类库:Struts2-core Struts2核心XWork-core xwork核心 Struts2的构 ...

  7. Hibernate的Session的get()和load()方法区别

    hibernate中Session接口提供的get()和load()方法都是用来获取一个实体对象,在使用方式和查询性能上有一些区别. get Session接口提供了4个重载的get方法,分别通过“持 ...

  8. luogu1129 [ZJOI2007]矩阵游戏

    其实,只用考虑某一行能否放到某一行就行了 #include <iostream> #include <cstring> #include <cstdio> usin ...

  9. System.TypeInitializationException

    在连接数据库时,提示System.TypeInitializationException 数据库的连接字符串放在config文件中,而config中有两个文件,起初放在debug.comfig中,启动 ...

  10. EXPDP/IMPDP任务的查看与管理

    EXPDP/IMPDP相比传统的exp/imp的最本质区别在于服务器端执行,客户端发出指定后,通过API启动服务器的备份job,在执行过程中,可以拿下Ctrl+C组合键,退出当前交互模式,退出之后,导 ...