最新用docker搭建wordpress 感谢chatGPT 指路明灯 人生导师
打造全网最快最好搭建wordpress,带域名带证书。对docker理解更加深刻。感谢chatGPT!
小白必须能学会的搭建方法!
重裝
bash <(wget --no-check-certificate -qO- 'https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh') -d 11 -v 64 -p lion123 -port 22
更新环境
apt update -y && apt upgrade -y && apt install -y curl wget sudo socat
安装 Docker
curl -fsSL https://get.docker.com | sh
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
创建wp目录,创建配置文件
cd /home/ && mkdir wp1 && cd wp1 && nano docker-compose.yml
搭建wp代码
version: '3.8'
services:
web:
image: nginx
ports:
- 80:80
- 443:443
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/certs:/etc/nginx/certs
wordpress:
image: wordpress
ports:
- 9000:80
environment:
WORDPRESS_DB_HOST: database
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress_password
volumes:
- ./wordpress-data:/var/www/html
database:
image: mysql
# image: arm64v8/mysql
# ARM使用上面的镜像 去掉井号 同时为image: mysql加上井号
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress_password
volumes:
- ./mysql:/var/lib/mysql
创建nginx容器所需目录
cd /home/wp1 && mkdir nginx && cd nginx && mkdir certs
进入目录,创建一个nginx配置文件
cd /home/wp1/nginx/ && nano nginx.conf
搭建反代代码
events {
worker_connections 1024;
}
http {
client_max_body_size 1000m;
#上传限制参数1G以内文件可上传
server {
listen 80;
server_name kjlion.gq;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name kjlion.gq;
ssl_certificate /etc/nginx/certs/cert.pem;
ssl_certificate_key /etc/nginx/certs/key.pem;
location / {
proxy_pass http://127.0.0.1:9000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
创建SSL证书,我是用CF的15年证书
cd /home/wp1/nginx/certs && nano cert.pem 公钥
cd /home/wp1/nginx/certs && nano key.pem 私钥
运行指令
cd /home/wp1 && docker-compose up -d
开机自启动
docker update --restart=always wp1-wordpress-1 && docker update --restart=always wp1-database-1 && docker update --restart=always wp1-web-1
备份打包
cd /home && tar -czvf wp1.tar.gz wp1/
迁移或还原
cd /home && tar xvzf wp1.tar.gz
Docker常用命令
https://kejilion.blogspot.com/2023/02/docker.html
输入你的域名即可访问你的wordpress
最终成品效果
这只是范例 数据库名称和密码 生产环境改的复杂点
最后送上与chatGPT的学习交流
评论
发表评论