世界,您好!

达成成就:一年内尝试重启博客三次 (3/3)。

记录一下搭建步骤,顺便测试一下语法高亮之类的。 _(:з」∠)_

WordPress

把下面的文件保存为 docker-compose.yml,直接用 docker-compose up -d 启动:

version: '3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     volumes:
       - wp-content:/var/www/html/wp-content
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
volumes:
    db_data:
    wp-content:

要备份的话只需要备份 docker 的两个 volumes 就好了。

然后安装一些插件:

Nginx

然后在主机上加一个反代。

upstream blog_docker {
    server 127.0.0.1:8000;
}

server {
        listen 80;
        listen [::]:80;
        listen 443 ssl http2;
        listen [::]:443 ssl http2;

        server_name blog.volltin.com;

        ssl_certificate /etc/nginx/ssl/fullchain.cer;
        ssl_certificate_key /etc/nginx/ssl/blog.volltin.com.key;

        access_log  /var/log/nginx/blog_access.log;
        error_log   /var/log/nginx/blog_error.log;

        location / {
            proxy_redirect off;
            proxy_pass http://blog_docker;
            include proxy_params;
        }
}

SSL

最后是用 acme.sh 配置一下证书:

申请证书:

acme.sh --issue -d blog.volltin.com --nginx

安装证书:

mkdir -p /etc/nginx/ssl
acme.sh --installcert -d blog.volltin.com --key-file /etc/nginx/ssl/blog.volltin.com.key --fullchain-file /etc/nginx/ssl/fullchain.cer --reloadcmd  "service nginx force-reload"

哒哒!然后就完成了。

基本情况就是这样。

一些杂项

强制跳转 HTTPS

加个 nginx 配置:

# /etc/nginx/sites-available/blog.volltin.com
server {
        listen 80;
        listen [::]:80;
        server_name blog.volltin.com;

        return 301 https://blog.volltin.com$request_uri;
}

然后重启 nginx 就行。

上传文件大小

默认好像是 2MB,通过修改下面两个地方改为更大:

# /etc/nginx/sites-available/blog.volltin.com
server {
    # ...
    client_max_body_size 64M;
}

下面的内容保存为 uploads.ini

file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600

然后更新 docker-compose.yml,把 PHP 配置挂进去:

wordpress:
     volumes:
       - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

最后重启就完事儿了:

sudo systemctl reload nginx
sudo docker-compose down
sudo docker-compose up -d
Comments
Add New Comment