跳转至

Ubuntu上安装配置Isso

Isso是基于Python写的一套网站评论系统,用于给网站添加评论功能,尤其类似于MKdocs、Hexo等生成的静态网站。使用Isso搭建评论服务,评论数据使用sqlite数据库保存。官方提供了很多种安装方式,本文使用PIP安装。

安装前置软件

安装PIP

PIP(Python Package Index) 是Python软件包管理系统,一般来说,PIP随着python一起安装的,所有只需要对pip升级到最新版即可:

1
pip install --upgrade pip

安装SQLite3

由于Isso的评论使用SQlite3数据库保存,需要安装:

1
apt install sqlite3
新建一个目录用来存放Isso的数据(sqlite3的存放目录),由于Isso运行过程中需要读写数据库,可以将该目录授予读写权限,顺便把文件所有者改为www-data(nginx的用户):
1
2
3
mkdir -p /home/isso
chmod -R 0777 /home/isso
chown -R www-data:www-data /home/isso 

安装python-dev build-essential

1
apt install python-dev build-essential

网站配置

修改静态页面所在的网站配置,增加isso的反代功能:

1
vi /etc/nginx/sites-enabled/zimoapps.com.conf
在其中的server字段增加:
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:8090;
}
顺便贴以下完整配置:
 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
server{
        root /var/www/zimoapps.com;
        index index.html index.htm index.nginx-debian.html;
        server_name zimoapps.com;
        location / {
                try_files $uri $uri/ =404;
        }
        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:8090;
        }
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/zimoapps.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/zimoapps.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
        if ($host = zimoapps.com) {
                return 301 https://$host$request_uri;
        } # managed by Certbot
        server_name zimoapps.com;
        listen 80;
        return 404; # managed by Certbot
}
保存退出后,需要重启nginx以使得先前的修改生效:
1
nginx -s reload

安装Isso

安装很简单,一句命令即可:

1
pip install isso

配置Isso

新建Isso的配置文件/home/isso/isso.conf:

1
vi /home/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
[general]
dbpath = /tmp/comments.db
name =
 host =
     http://zimoapps.com/
     https://zimoapps.com/
max-age = 15m
notify = smtp
reply-notifications = true
log-file =
gravatar = false
gravatar-url = https://www.gravatar.com/avatar/{}?d=identicon
latest-enabled = false

[admin]
enabled  = true
password = mypass

[moderation]
enabled = false
approve-if-email-previously-approved = false
purge-after = 30d

[server]
listen = http://localhost:8080
public-endpoint =
trusted-proxies =

[smtp]
username = service@zimoapps.com
password = mypassowrd
host = smtp.mxhichina.com
port = 465
security = ssl
to = zimo@zimoapps.com
from = "zimo comments" <service@zimoapps.com>
timeout = 10

[guard]
enabled = true
ratelimit = 2
direct-reply = 3
reply-to-self = false
require-author = false
require-email = false

[markup]
options = strikethrough, autolink, fenced_code, no_intra_emphasis
flags =
allowed-elements =
allowed-attributes =

[hash]
salt = Eech7co8Ohloopo9Ol6baimi
algorithm = pbkdf2

[rss]
base =
limit = 100
以上是我的配置,可以参考着修改,也可以使用官方的默认配置
配置完成后,可以使用命令来启动Isso了:
1
isso -c /home/isso/isso.conf run
1
2
2021-02-03 21:07:02,752 INFO: connected to SMTP server
2021-02-03 21:07:02,786 INFO: connected to https://zimoapps.com/
能看到类似上面的界面,说明Isso已经成功运行了。

注意

可能运行会报错:

1
2
3
4
5
File "/usr/local/bin/isso", line 5, in <module>
from isso import main
File "/usr/local/lib/python3.8/dist-packages/isso/__init__.py", line 59, in <module>
from werkzeug.wsgi import SharedDataMiddleware
ImportError: cannot import name 'SharedDataMiddleware' from 'werkzeug.wsgi' (/usr/local/lib/python3.8/dist-packages/werkzeug/wsgi.py)
解决办法是降低werkzeug的版本号,使用低版本:
1
2
3
cd /home/isso/
pip freeze > requirements.txt
vi requirements.txt
在打开的requirements.txt中,修改Werkzeug==0.16.1,保存退出。
1
pip install -r requirements.txt
执行完毕后,再次运行isso。

安装 Supervisor

Supervisor 是一款进程守护软件,目的是保持 Isso 在后台运行。

1
pip install supervisor
生成一份supervisor的配置到/etc/supervisord.conf
1
echo_supervisord_conf > /etc/supervisord.conf
VI修改/etc/supervisord.conf
1
vi /etc/supervisord.conf
/etc/supervisord.conf文件的后面加入:
1
2
3
4
5
6
7
8
[program:isso]
command = /usr/local/bin/isso -c /etc/isso.conf run
directory = /home/isso
user = www-data
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/isso.log
stderr_logfile = /var/log/supervisor/isso_error.log
新建日志的存放目录:
1
mkdir -p /var/log/supervisor
启动Supervisor:
1
supervisord -c /etc/supervisord.conf
使用:
1
curl https://zimoapps.com/isso/
查看运行结果,能看到类似的内容,所有已经成功运行了:
1
2
3
4
5
6
7
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>

Supervisor简单命令

1
2
supervisord -c /etc/supervisord.conf             # 启动进程
supervisorctl -c /etc/supervisord.conf shutdown  # 关闭运行的supervisord进程,非软件进程

备注

1
本文中的静态页面网站先前已经配置了https,所以涉及到域名相关的输入时,均使用https前缀。

前端页面配置Isso

到现在,Isso的服务端已经成功配置并运行,为了展示并提交评论,需要在前端页面中显示isso的评论相关内容。需要在前端相关页面的位置中插入Isso的运行代码:

1
2
<script data-isso="https://zimoapps.com/isso/" src="https://zimoapps.com/isso/js/embed.min.js"></script>
<section id="isso-thread"></section>
根据不同页面,不同需求,不同的页面生成程序,使用起来略有区别,建议仔细阅读响应文档。
对于Mkdocs,或者Mkdocs的Material for MkDocs主题,修改./overrides/base.html{% block disqus %}部分:
1
2
3
4
{% block disqus %}
    <script data-isso="https://zimoapps.com/isso/" src="https://zimoapps.com/isso/js/embed.min.js"></script>
    <section id="isso-thread"></section>
{% endblock %}
以上只是一个最基本的配置,完整的如下:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<script data-isso="/prefix/"
        data-isso-id="thread-id"
        data-isso-css="true"
        data-isso-lang="ru"
        data-isso-reply-to-self="false"
        data-isso-require-author="false"
        data-isso-require-email="false"
        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-isso-vote-levels=""
        data-isso-feed="false"
        src="/prefix/js/embed.js"></script>
更具体的配置请前往官方文档

最后,本站未必采用这个评论系统,所以,先贴个效果图!