您的位置 首页 php

windows 10 下docker布置nginx+php环境,用宿主WEB目录负载均衡

实现目的:windows 10下安装 docker ,布置 nginx +php5.6运行环境,布置多个docker实现 负载均衡 ,实现成功,存在缺点windows server版本需要付费,当做测试学习,正式服务器可以考虑linux系统;

参考资料:

docker可以简单理解为一个虚拟的的ubuntu系统,操作基本都是通过命令行来操作的,有一个虚拟的交换机接入网络

docker与虚拟机的区别可以查看:

获取nginx最新版本镜像image:

docker pull nginx

启动一个nginx的docker,docker内部是80端口理解为端口映射到外网808端口:

docker run -d -p 808:80 –name mynginx nginx

获取php5.6的镜像文件:

docker pull php:5.6.40-fpm

启动php,将宿主web目录映射到phpweb服务器目录,目录与下面nginx要一致:

docker run -d -v E:\docker\www:/var/www/html -p 9000:9000 –name myphp php:5.6.40-fpm

复制docker配置文件到windows:

docker cp myphp:/usr/local/etc E:\docker\php-conf

docker cp myphp:/usr/local/var/log E:\docker\php-log

docker cp myphp:/var/www/html E:\docker\www

安装php扩展

apt-get update

docker-php-ext-install pdo_mysql

docker-php-ext-install mysql

docker-php-ext-install gd

docker-php-ext-install curl

php配置完成,启动:

docker run -d -v E:\docker\php-conf:/usr/local/etc -v E:\docker\php-log:/usr/local/var/log -v E:\docker\www:/var/www/html -p 9000:9000 –name myphp php:5.6.40-fpm

复制nginx的配置到windows

docker cp mynginx:/etc/nginx E:\docker\nginx-conf

E:\docker\nginx-conf下面的nginx目录文件都copy到上一级

按照下面修改:E:\docker\nginx-conf\conf.d\default.conf

docker run -d -p 808:80 -v E:\docker\www:/var/www/html -v E:\docker\nginx-conf:/etc/nginx/ -v E:\docker\nginx-log:/var/log/nginx/ –link myphp:php –name mynginx nginx

到此成功success

=============================

Docker的Ubuntu镜像安装的容器无ifconfig命令和ping命令

进入docker命令行

docker exec -it mynginx /bin/sh

解决:

apt-get update

apt install net-tools # ifconfig

apt install iputils-ping # ping

=================================

default.conf

server {

listen 80;

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 /usr/share/nginx/html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

root /var/www/html;

fastcgi_pass php:9000;

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;

#}

}

文章来源:智云一二三科技

文章标题:windows 10 下docker布置nginx+php环境,用宿主WEB目录负载均衡

文章地址:https://www.zhihuclub.com/152009.shtml

关于作者: 智云科技

热门文章

网站地图