<返回更多

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

2020-07-29    
加入收藏
https://www.isolves.com/it/rj/czxt/windows/2020-07-28/25782.html

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

参考资料:https://www.cnblogs.com/lxd-ld/p/11578467.html?tt_from=copy_link&utm_source=copy_link&utm_medium=toutiao_IOS&utm_campaign=client_share

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

docker与虚拟机的区别可以查看:https://zhuanlan.zhihu.com/p/74491259

获取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:dockerwww:/var/www/html -p 9000:9000 --name myphp php:5.6.40-fpm

复制docker配置文件到windows:

docker cp myphp:/usr/local/etc E:dockerphp-conf

docker cp myphp:/usr/local/var/log E:dockerphp-log

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

安装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:dockerphp-conf:/usr/local/etc -v E:dockerphp-log:/usr/local/var/log -v E:dockerwww:/var/www/html -p 9000:9000 --name myphp php:5.6.40-fpm

复制nginx的配置到windows

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

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

按照下面修改:E:dockernginx-confconf.ddefault.conf

docker run -d -p 808:80 -v E:dockerwww:/var/www/html -v E:dockernginx-conf:/etc/nginx/ -v E:dockernginx-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 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;

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目录负载均衡

 

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>