在 ArchLinux 服务器上搭建 sub-web

本文最后更新于 2022年3月29日 晚上

sub-web 是一个基于 vue-cli 与 tindy2013/subconverter 后端实现的配置自动生成工具。我以前一直用的别人搭建的网站进行转换,但是总觉得不安全,因此今天心血来潮想要自己搭建一个 sub-web 来进行 clash 订阅链接转换。

构建 sub-web

根据 Github 上的说明,我们只需要把仓库克隆下来,然后安装依赖,再 build 就行了。

先克隆仓库到本地并进入

1
2
git clone https://github.com/CareyWang/sub-web.git/
cd sub-web/

安装依赖

1
yarn install

结果突然就报错了

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
error /home/sukanka/Downloads/sub-web/node_modules/node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: /home/sukanka/Downloads/sub-web/node_modules/node-sass
Output:
Building: /usr/bin/node /home/sukanka/Downloads/sub-web/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli '/usr/bin/node',
gyp verb cli '/home/sukanka/Downloads/sub-web/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli 'rebuild',
gyp verb cli '--verbose',
gyp verb cli '--libsass_ext=',
gyp verb cli '--libsass_cflags=',
gyp verb cli '--libsass_ldflags=',
gyp verb cli '--libsass_library='
gyp verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@15.14.0 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed at getNotFoundError (/home/sukanka/Downloads/sub-web/node_modules/which/which.js:13:12)
gyp verb `which` failed at F (/home/sukanka/Downloads/sub-web/node_modules/which/which.js:68:19)
gyp verb `which` failed at E (/home/sukanka/Downloads/sub-web/node_modules/which/which.js:80:29)
gyp verb `which` failed at /home/sukanka/Downloads/sub-web/node_modules/which/which.js:89:16
gyp verb `which` failed at /home/sukanka/Downloads/sub-web/node_modules/isexe/index.js:42:5
gyp verb `which` failed at /home/sukanka/Downloads/sub-web/node_modules/isexe/mode.js:8:5
gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:193:21)
gyp verb `which` failed python2 Error: not found: python2
gyp verb `which` failed at getNotFoundError (/home/sukanka/Downloads/sub-web/node_modules/which/which.js:13:12)
gyp verb `which` failed at F (/home/sukanka/Downloads/sub-web/node_modules/which/which.js:68:19)
gyp verb `which` failed at E (/home/sukanka/Downloads/sub-web/node_modules/which/which.js:80:29)
gyp verb `which` failed at /home/sukanka/Downloads/sub-web/node_modules/which/which.js:89:16
gyp verb `which` failed at /home/sukanka/Downloads/sub-web/node_modules/isexe/index.js:42:5
gyp verb `which` failed at /home/sukanka/Downloads/sub-web/node_modules/isexe/mode.js:8:5
gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:193:21) {
gyp verb `which` failed code: 'ENOENT'
gyp verb `which` failed }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python /usr/bin/python
gyp ERR! configure error
gyp ERR! stack Error: Command failed: /usr/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack File "<string>", line 1
gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (node:child_process:326:12)
gyp ERR! stack at ChildProcess.emit (node:events:369:20)
gyp ERR! stack at maybeClose (node:internal/child_process:1067:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
gyp ERR! System Linux 5.11.11-arch1-1
gyp ERR! command "/usr/bin/node" "/home/sukanka/Downloads/sub-web/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /home/sukanka/Downloads/sub-web/node_modules/node-sass
gyp ERR! node -v v15.14.0

挺突然的,不过看日志好像和 node-sasspython2 有关。可以尝试安装 python2 (经尝试确实可以,但是很慢)。但是既然 Arch 都默认 python3 了,我们肯定不能再装回 python2,那就在 node-sass 上找原因。

找到 node-sass主页,发现最新版已经是 5.0.0 了,但是依赖的是 4.13.0。直接在 package.json 中进行修改

1
2
-- "node-sass": "^4.13.0",
++ "node-sass": "^5.0.0",

然后删除 node_modules,重新进行 yarn install 就没问题了。

然后就可以运行 yarn build 来构建用于线上环境的版本了。

我将 build/dist 中的文件全部上传到 /var/www/sub-web/中,按照 github 上的说明就配置好了前端。

配置后端

首先安装 subconverter-bin

1
yay -S subconverter-bin

但是这个包不带 systemd 服务,我们自己写一个服务,往 /etc/systemd/system/subconverter.service 写入如下内容:

记得把 YOUR_USER 改成你的用户名。

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Sub Converter
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=YOUR_USER
ExecStart=/usr/bin/subconverter

[Install]
WantedBy=multi-user.target

然后运行如下命令以启动(并开机自启)服务

1
2
sudo systemctl daemon-reload
sudo systemctl enable --now subconverter.service

配置域名

按照 github 上的说明可以配置好前端,但是我们还需要配置后端。我是这样写的

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
server {
server_name sub.example.com; # 注意替换域名

root /var/www/sub-web/;
index index.html index.htm;

error_page 404 /index.html;

gzip on; #开启gzip压缩
gzip_min_length 1k; #设置对数据启用压缩的最少字节数
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 6; #设置数据的压缩等级,等级为1-9,压缩比从小到大
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml; #设置需要压缩的数据格式
gzip_vary on;

# 这里是代理到后端端口
location /sub {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto $scheme;
proxy_redirect off;
proxy_pass http://127.0.0.1:25500;

}
location ~* \.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)$ {
access_log off;
add_header Cache-Control "public,max-age=30*24*3600";
}

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/sub.sukanka.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/sub.sukanka.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

}

其中, https 是用 certbot 自动管理的, 具体参见 ArchWiki-Certbot

至此,我们就配置好了前端和后端,可以正常使用了,但是我发现生成的链接特别长(需要配置短链),同时,规则特别少,不如别人的舒服(需要配置 远程配置)。

短链

基于 MyUrls, 参考 MyUrls 短链服务部署。先空着。

远程配置

暂时没搞明白,先放着,参考 ACL4SSR,与 https://www.v2rayssr.com/sub-web.html


在 ArchLinux 服务器上搭建 sub-web
https://blog.askk.cc/2021/04/09/sub-web-on-archlinux/
作者
sukanka
发布于
2021年4月9日
许可协议