利用docker建立个人博客站点-Wordpress

 

1、重裝系统

bash <(wget --no-check-certificate -qO- 'https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh') -d 11 -v 64 -p kejixiaoxin123 -port 22

-p 后面为root密码

2、更新环境

apt update -y  && apt upgrade -y && apt install -y curl wget sudo socat

3、安装 Docker

curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
curl -L "https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

4、创建wp目录,创建配置文件

cd /home/ && mkdir wp1 && cd wp1 && nano docker-compose.yml

5、搭建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: kejixiaoxinwordpress_password123

    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: kejixiaoxinwordpress_password123

    volumes:

      - mysql:/var/lib/mysql



volumes:

  wordpress-data:

  mysql:

6、创建nginx容器所需目录

cd /home/wp1 && mkdir nginx && cd nginx && mkdir certs

7、进入目录,创建一个nginx配置文件

cd /home/wp1/nginx/ && nano nginx.conf

8、搭建反代代码

events {

    worker_connections  1024;


}



http {



  client_max_body_size 1000m;  


  #上传限制参数1G以内文件可上传


  server {

    listen 80;

    server_name blg.kejixiaoxin.click;

    return 301 https://$host$request_uri;

  }

  server {

    listen 443 ssl http2;

    server_name blg.kejixiaoxin.click;

    ssl_certificate /etc/nginx/certs/cert.pem;

    ssl_certificate_key /etc/nginx/certs/key.pem;

    location / {

      proxy_pass http://23.251.54.165: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;

    }

  }

}

9、创建SSL证书,我是用CF的15年证书

cd /home/wp1/nginx/certs && nano cert.pem        公钥
cd /home/wp1/nginx/certs && nano key.pem         私钥

10、运行指令

cd /home/wp1 && docker-compose up -d

11、开机自启动

docker update --restart=always wp1-wordpress-1 && docker update --restart=always wp1-database-1 && docker update --restart=always wp1-web-1

其他:

1、备份

cd /home && tar -czvf wp1.tar.gz wp1/

2、迁移&还原

cd /home && tar xvzf wp1.tar.gz

评论

此博客中的热门博文

始终免费的vps!甲骨文云(oracle)抢注册高性能ARM实例!一键脚本部署!

LINUX | 谷歌云开启SSH及设置root密码