建设目标,利用docker技术快速搭建wordpress和dedecms,完成多域名的部署工作。
操作时间评估:20分钟。
主要部署内容,php7,nginx,myssql,wordpress,dedecms。
主要操作过程,几个命令行。
安装环境,安装有docker的服务主机(国外主机),本文略过安装过程。
项目要求,有三个网站,如下要求。
- www.a.com,使用dedecms
- www.b.com,使用wordpress
- www.c.com,静态网站
主要思想,分别安装dedecms和wordprss,再利用nginx转发思想,分别建立转发机制。
操作过程:
第一步:准备工作,
根目录: /opt/docker
网站根目录:/opt/docker/www
nginx相关目录:/opt/docker/nginx/conf.d
第二步:安装php7,nginx,mysql
//取得nginx镜像
docker pull nginx
//取得php镜像
docker pull php:7.1.0-fpm
//取得mysql镜像
docker pull mysql
第三步:启动基础环境
//启动php
docker run -p 9000:9000 --name myphp \
-v /docker/www/:/var/www/html/ \
--privileged=true \
-d php:7.1.0-fpm
//启动nginx
docker run -p 80:80 --name mynginx \
-v /docker/www:/usr/share/nginx/html \
-v /docker/nginx/conf.d:/etc/nginx/conf.d \
--privileged=true \
-d nginx
//启动mysql
docker run -d -e MYSQL_ROOT_PASSWORD=yaya --name wp-mysql -v /opt/docker/mysql/data:/var/lib/mysql -p 3306:3306 mysql
第四步:安装dedecms
//取得deducts镜像
docker pull chengxulvtu/dedecms:utf8_full_5.7
或
docker pull chengxulvtu/dedecms:gbk_full_5.7
//运行dedecms
docker run -d --name dede-lantinghe -p 8081:80 -v /opt/docker/www/dedecms/:/var/www/html chengxulvtu/dedecms:utf8_full_5.7
第五步,安装wordpress
#取得wordpress镜像
docker pull wordpress
#运行wordpress镜像
docker run -d --name wp-lantinghe --link wp-mysql:mysql -v /opt/docker/www/wordpress/:/var/www/html/ -p 8080:80 wordpress
第六步,分别配置各域名
文件/opt/docker/nginx/conf.d/a.com.conf
server {
listen 80;
server_name www.a.com;
root /usr/share/nginx/html/dedecms/;
location / {
index index.html index.htm index.php;
autoindex off;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://x.x.x.x:8081;
}
location ~ \.php(.*)$ {
fastcgi_pass 172.17.0.2:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
文件/opt/docker/nginx/conf.d/b.com.conf
server {
listen 80;
server_name www.b.com;
root /usr/share/nginx/html/wordpress/;
location / {
index index.html index.htm index.php;
autoindex off;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://x.x.x.x:8080;
}
location ~ \.php(.*)$ {
fastcgi_pass 172.17.0.2:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
文件/opt/docker/nginx/conf.d/c.com.conf
server {
listen 80;
server_name www.c.com;
root /usr/share/nginx/html/c.com/;
location / {
index index.html index.htm index.php;
autoindex off;
}
}
最后重启nginx
docker restart mynginx
上面所有功能完成,三个网站均可以正常访问。