使用docker-compose &WordPress建站

JJLAAA 2021-02-23 16:08:14
docker 使用 WordPress compose docker-compose


使用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文件一致
版权声明
本文为[JJLAAA]所创,转载请带上原文链接,感谢
https://segmentfault.com/a/1190000039262859

  1. Deep understanding of Web protocol (3): http 2
  2. Tencent IEG open source AI SDK: automatic testing of chicken eating and MoBa games
  3. Mysql Command
  4. Docker dockerfile create image
  5. Redis Cluster
  6. 死磕Spring之IoC篇 - 文章导读
  7. Deep understanding of Web protocol (3): http 2
  8. JavaScript BOM operation
  9. JavaScript BOM operation
  10. 死磕Spring之IoC篇 - 文章导读
  11. k8s node 操作与维护
  12. k8s 证书更新
  13. 【Java面试题第三期】JVM中哪些地方会出现内存溢出?出现的原因是什么?
  14. HashMap连环问你能答出几道?
  15. k8s-cronjob
  16. k8s-cert
  17. 头条面试官:说说Kafka的消费者提交方式,怎么实现的
  18. 什么是HTTPS以及如何实施HTTPS?
  19. Spring: an introduction to IOC
  20. Spring: an introduction to IOC
  21. Operation and maintenance of k8s node
  22. K8s certificate update
  23. vue使用sdk进行七牛上传
  24. k8s-dns
  25. JavaScript 邮箱验证 - 正则验证
  26. k8s-dashboard
  27. HashMap连环问你能答出几道?
  28. Where does memory overflow occur in the JVM? What are the reasons for this?
  29. How many questions can you answer?
  30. k8s-cronjob
  31. spring注解--Transactional
  32. k8s-cert
  33. Will the Spring Festival holiday be extended to February 27 in 2021? Here comes the response
  34. Headline Interviewer: talk about Kafka's consumer submission method, how to achieve it
  35. 【k8s集群】搭建步骤
  36. k8s-kubeadm
  37. k8s-etcd
  38. What is HTTPS and how to implement it?
  39. Java中使用HashMap改进查找性能
  40. maven发布jar包运行时找不到类问题
  41. J2EE
  42. Vue uses SDK to upload seven cows
  43. k8s-dns
  44. JavaScript mailbox verification - regular verification
  45. k8s-dashboard
  46. How many questions can you answer?
  47. Spring annotation -- transactional
  48. [k8s cluster] construction steps
  49. k8s-kubeadm
  50. k8s-etcd
  51. Using HashMap to improve search performance in Java
  52. There is no class problem when Maven publishes jar package
  53. JavaScriptBOM操作
  54. J2EE
  55. k8s-prometheus-memory
  56. k8s-prometheus disk
  57. k8s-prometheus
  58. JavaScript BOM operation
  59. k8s-prometheus-memory
  60. k8s-prometheus disk