前言
waline 是由lizheming 开发的博客评论系统,从Valine 衍生的带后端评论系统。可以将Waline
等价成With backend Valine
。
Waline的服务端可以部署在Vercel 、CloudBase 或者服务器上,数据库可以使用LeanCloud 、MySQL等,总计有多达48钟部署方式。在官方教程中,使用云服务部署都介绍的比较详细,下面介绍两种本地部署方式,可以自定义端口,配合多种数据库使用。
Docker
在Docker容器内运行vanilla.js
文件。
修改Node.js
淘宝源
1 2 3 4 5 6 npm install module_name --registry=https://registry.npm.taobao.org npm config set registry https://registry.npm.taobao.org npm install -g cnpm --registry=https://registry.npm.taobao.org
构建镜像
1 2 3 git clone https://github.com/lizheming/waline.git cd walinedocker build -t image_name -f packages/server/Dockerfile .
修改配置packages/client/.env
,参考文档中所需环境变量配置即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 SKIP_PREFLIGHT_CHECK=true MYSQL_HOST=127.0.0.1 MYSQL_DB=db_name MYSQL_USER=db_user MYSQL_PASSWORD=password AKISMET_KEY=guess SITE_NAME=Fox Home SITE_URL=https://foolishfox.cn AUTHOR_EMAIL=fox@foolishfox.cn SC_KEY=SCK232027Td54bfab83cfabf0aereq2c31b6552cd35fe1a43720074 SMTP_HOST=smtp.ym.163.com SMTP_PORT=465 SMTP_USER=fox@foolishfox.cn SMTP_PASS=password SENDER_NAME=fox SENDER_EMAIL=fox@foolishfox.cn
运行镜像
1 docker run --env-file ./packages/client/.env -p 8360:8360 -d image_name
设置反向目录代理,将waline.foolishfox.cn
指向127.0.0.1:8360
进入容器
1 2 3 4 5 6 root@iZ2ze8k2vy63cz277rsw8zZ:$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cebd15a83483 lizheming/waline "docker-entrypoint.s…" 44 seconds ago Up 42 seconds 0.0.0.0:8360->8360/tcp admiring_noether root@iZ2ze8k2vy63cz277rsw8zZ:$ docker exec -it cebd15a83483 /bin/bash
安装vim
(可跳过)与验证组件
1 2 3 apt update apt install vim apt install apt-transport-https ca-certificates
更新软件源(使用清华源 )
1 2 3 4 5 6 7 8 9 mv /etc/apt/sources.list /etc/apt/sources.list.bakvim /etc/apt/sources.list echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free" >/etc/apt/sources.listapt update ...
1 2 3 4 5 6 7 8 9 # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
配置config.js
,路径为:node_modules/@waline/vercel/config.js
,参考服务端配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 module .exports = { secureDomains : [ 'foolishfox.cn' , 'waline.foolishfox.cn' , 'localhost' , '127.0.0.1' ], forbiddenWords : [ '空包' , '快递' , '下单' ], disallowIPList : [ '8.8.8.8' ] };
修改主程序vanilla.js
,导入自定义配置
1 2 3 4 5 6 7 8 const path = require ('path' );const Application = require ('thinkjs' );... let config = {}try { config = require ('./config.js' ); } catch (e) {} ...
直接部署
直接部署方便对配置进行修改,不需要更新镜像,安装好模块后使用Node.js
运行模块内的vanilla.js
文件即可。
安装waline
1 2 mkdir walinejs && cd walinejscnpm install @waline/vercel --save
编辑.bashrc
,添加环境变量,最好将字符串用"
或者'
包起来,避免$
、&
等字符的影响
1 2 3 MYSQL_HOST='rm-*.mysql.rds.aliyuncs.com' ... SENDER_EMAIL='fox@foolishfox.cn'
创建软链接,方便后续操作
1 2 ln -s node_modules/@waline/vercel ./walinecd waline
配置服务端vim config.js
,见上
修改主程序vanilla.js
,见上
使用pm2运行程序
1 2 cnpm install -g pm2 pm2 start vanilla.js --name waline
设置反向目录代理,将waline.foolishfox.cn
指向127.0.0.1:8360
前端配置
参考文档 ,需要注意的有:
本地(localhost)访问不增加计数(以hexo
为例)
1 2 3 4 5 6 new Waline ({ el : '#waline' , path : location.pathname , serverURL : 'https://your-serverURL.domain.com' , visitor : location.hostname !=='localhost' && !{ theme.waline .visitor } });
参考资料
waline
博客服务器迁移过程
pm2入门