使用docker-compose &WordPress建站

使用docker-compose &WordPress建站

安装docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.28.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose
  • 如果出现网络问题,直接用浏览器下载可执行文件放到/usr/local/bin目录下即可

准备配置文件

  • 为WordPress提供HTTPS支持的Nginx配置文件

    mkdir -p  /root/wordpress/nginx/conf && mkdir -p  /root/wordpress/nginx/ssl \
    echo 'server {
        listen 80;
        server_name ${host_name};
        rewrite ^(.*)$  https://${host_name}$1 permanent;
    }
    
    server {
        listen          443 ssl;
        server_name     ${host_name};
    
        #ssl证书文件位置(常见证书文件格式为:crt/pem)
        ssl_certificate      /etc/nginx/ssl/cert.pem;
        #ssl证书key位置
        ssl_certificate_key  /etc/nginx/ssl/cert.key;
        ssl_session_timeout  10m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_prefer_server_ciphers  on;
    
        location / {
             proxy_pass    http://wordpress;
             proxy_cache_bypass                 $http_upgrade;
    
             # Proxy headers
             proxy_set_header Upgrade           $http_upgrade;
             proxy_set_header Connection        "upgrade";
             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_set_header X-Forwarded-Proto $scheme;
             proxy_set_header X-Forwarded-Host  $host;
             proxy_set_header X-Forwarded-Port  $server_port;
    
             # Proxy timeouts
             proxy_connect_timeout              600s;
             proxy_send_timeout                 600s;
             proxy_read_timeout                 600s;
        }
    }' >> /root/wordpress/nginx/conf/route.conf
    • 证书可以从阿里云免费申请,绑定到对应的${host_name}域名即可,并放置到/root/wordpress/nginx/ssl/目录下(可以自由修改,注意与下边的yaml文件保持一致即可)
  • docker-compose yaml配置文件

    echo 'version: '3.1'
    
    services:
    
      nginx: 
        image: nginx
        container_name: wp_nginx
        restart: always
        ports:
          - 443:443
          - 80:80
        volumes:
          - /root/wordpress/nginx/conf:/etc/nginx/conf.d/
          - /root/wordpress/nginx/ssl/:/etc/nginx/ssl/
      wordpress:
        image: wordpress
        container_name: wp
        restart: always
        environment:
          WORDPRESS_DB_HOST: db
          WORDPRESS_DB_USER: wp
          WORDPRESS_DB_PASSWORD: wp_db_lee
          WORDPRESS_DB_NAME: wp_db
        volumes:
          - wordpress:/var/www/html
    
      db:
        image: mysql:5.7
        container_name: wp_mysql
        restart: always
        environment:
          MYSQL_DATABASE: wp_db
          MYSQL_USER: wp
          MYSQL_PASSWORD: wp_db_lee
          MYSQL_RANDOM_ROOT_PASSWORD: '1'
        volumes:
          - db:/var/lib/mysql
    
    volumes:
      wordpress:
      db:' >> /root/wordpress/wordpress.yaml \
    docker-compose -f wordpress.yaml up -d

配置网络与域名

  • 只需要在域名提供商,为自己购买的域名,添加A类型的子域名记录比如blog.demoli.xyz,然后将解析值设置为自己服务器的公网IP即可

推荐安装插件

  • All-in-One WP Migration 迁移站点
  • Post Views Counter 查看阅读数
  • UpdraftPlus-备份/恢复 备份站点
  • WP Githuber MD Markdown在线编辑
  • Yoast SEO SEO设置

插件安装的问题

  • 插件安装出现网络错误时,可以进入插件官网,手动下载文件上传到指定文件夹安装,使用docker cp命令导入到容器即可。
  • 注意导入后,进入容器将导入的文件或文件夹的owner 与 group与其他WordPress文件一致

你可能感兴趣的:(使用docker-compose &WordPress建站)