搭建Isso自建评论系统

搭建Isso自建评论系统

之前博客的评论系统一直用的是 Disqus,但是 Disqus 在国内被墙了,必须通过代理才能访问,这导致在国内的体验不是很好。工信部又发通知不允许第三方平台提供非注册用户发表评论跟帖的功能,于是多说、网易云跟帖这些评论平台也快速倒闭。韩国还有一个来必力可以用,但是个人无感。

最终打算使用 Isso 搭建自建评论系统,具体介绍见官网简介,我这里直接记录搭建过程。

安装 Isso

1
2
yum install sqlite python36-devel # 安装依赖 (python36-devel用于 gcc 编译 misaka 插件)
python3 -m pip install isso --user # 安装 isso

配置 Isso

在用户目录下新建一个 isso 文件夹,isso.conf 配置文件(用来配置 isso),其中 isso.conf 的内容示例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 通用配置
[general]
# 数据库文件路径,把 /root/ 替换成你自己的用户路径 (必填)
dbpath = /root/isso/data.db
# 配置文件的名字,如果该服务器上只搭建一个 Isso 的话可以忽略,搭建多个 Isso 的话需要设置 (可选)
name = blog
# 是你引用 Isso JavaSript 文件的博客地址,需要写全,如果有的话就多加几行,只有一个域名的话留下一个即可 (必填)
host = https://lolimay.cn
https://www.lolimay.cn
# 是否开启邮件通知,设置了 SMTP 就要在下面的 [smtp] 设置右键发送方式 (可选)
notify = smtp
# 日志文件路径 (可选)
log-file = /root/isso/log

# 服务器配置
[server]
# 本地监听端口号
listen = http://localhost:53051/

# 评论审核
[moderation]
# 是否开启邮件审核,这里直接关闭了
enabled = false
# 在审核队列中的邮件,超时30天未审核直接移除
purge-after = 30d

# 你自己的 SMTP 配置,我这里使用的是 QQ 邮箱服务
[smtp]
# SMTP 用户名
username = service@lolimay.cn
# SMTP 密码
password = <替换成你的SMTP密码>
# SMTP 域名
host = smtp.qq.com
# SMTP 端口
port = 465
# SMTP 加密方式,选项有 ssl, starttls (TLS) QQ邮箱不支持 TLS 请使用 ssl 选项
security = ssl
# 接受邮件通知的邮箱
to = shiqi.mei@lolimay.cn
# 标题
from = "Isso 评论"<service@lolimay.cn>
# 超时
timeout = 10

# Misaka Markdown 插件
[markup]
# 选项
options = strikethrough, superscript, autolink
# 评论允许的 HTML 标签,默认允许的有 a, blockquote, br, code, del, em, h1, h2, h3, h4, h5, h6, hr, ins, li, ol, p, pre, strong, table, tbody, td, th, thead, ul,可以根据自己的情况修改
allowed-elements =
# 评论允许的 HTML 标签属性,默认只允许 align 和 href
allowed-attributes =

# 防火墙配置
[guard]
# 是否开启防火墙,可以防止被恶意评论
enabled = true
# 访客每分钟评论次数
ratelimit = 10
# 评论回复次数
direct-reply = 100
# 是否可以回复自己的评论
reply-to-self = true
# 是否要求写名字
require-author = true
# 是否要求写 email 地址
require-email = true

# 加密选项
[hash]
# 加密评论的身份方式,如 email 地址,没有特殊需求可以忽略这项
salt = Eech7co8Ohloopo9Ol6baimi
algorithm = pbkdf2

保存配置文件后,就可以启动 isso 看输出消息是否正常:

1
isso -c ~/isso/isso.conf

检查日志文件,查看是否有错误信息:

1
cat ~/isso/log

预期内容如下,如果日志输出不是类似下面这个内容,则需要手动排错:

1
2
connected to SMTP server
connected to https://lolimay.cn

配置 Nginx 反向代理 Isso 服务

修改网站的 Nginx 配置,添加代理规则:

1
2
3
4
5
6
7
location /isso/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Script-Name /isso;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:53051/;
}

保存后访问,https://lolimay.cn/isso 或者 https://www.lolimay.cn/isso 后显示:

1
2
Bad Request
missing uri query

就表示反向代理配置成功了,如果都没问题,就可以 Ctrl+C 先停止 Isso 了。

使用 pm2 部署 Isso

1
2
pm2 start python3 --name "isso" -- /usr/local/bin/isso -c /root/isso/isso.conf
pm2 save # 保存当前进程列表,这样即使系统重启后也会自动恢复

在博客源码中引用

1
2
3
4
5
6
7
<% if (page.comments) { %>
<!-- 部分配置需要和后端的 isso.conf 中的配置一致 -->
<script data-isso="/isso/" src="/isso/js/embed.min.js" data-isso-css="true"
data-isso-reply-to-self="true" data-isso-require-author="true" data-isso-require-email="true"
data-isso-max-comments-top="10" data-isso-max-comments-nested="5" data-isso-reveal-on-click="5" data-isso-avatar="true" data-isso-avatar-bg="#f0f0f0" data-isso-avatar-fg="#9abf88 #5698c4 #e279a3 #9163b6" data-isso-vote="true" data-vote-levels=""></script>
<section id="isso-thread"></section>
<% } %>

最后重新部署博客不出意外应该就可以看到成果了:

当然,如果你觉得自带的样式太简陋的话可以自己写一点 CSS 覆盖即可。

参考链接

  1. Debian / Ubuntu 搭建 Isso 评论系统教程