• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

基于Docker搭建Php-fpm+Nginx环境

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1、拉取nginx镜像,以及php-fpm镜像

docker pull nginx:1.16.0
docker pull php:5.6.40-fpm

2、分别创建nginx 容器php-fpm 容器

# 这里最后吧 /etc/nginx/conf.d 目录和存放静态资源文件的目录挂载到宿主机上来
docker run -d --name nginx_1_16_0 --link php_fpm_5_6_40:php_fpm_5_6_40 nginx:1.16.0

# 这里可以把 存储代码的目录也挂载到宿主机上
docker run -d --name php_fpm_5_6_40 php:5.6.40-fpm

3、参考下例编写 nginx 配置文件

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /var/www/html;
        index  index.html index.htm index.php;
    }

    #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   /var/www/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; # php-fpm 容器代码存放路径
        fastcgi_pass   php_fpm_5_6_40:9000; # php_fpm_5_6_40 是启动nginx时候link参数第二个值
        fastcgi_index  index.php;
        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;
    }
}

4、重启nginx容器

docker restart <容器ID>

参考链接:

https://blog.csdn.net/qq_35765928/article/details/87715448

https://blog.csdn.net/qq_38711879/article/details/105407750


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP去除换行符与PHP_EOL变量的使用发布时间:2022-07-10
下一篇:
PHPini配置无效的坑给自己记录发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap