Kutt部署手册

记录部署 kutt 工具过程

项目简介

Kutt is a modern URL shortener with support for custom domains. Shorten URLs, manage your links and view the click rate statistics.

thedevs-network/kutt: Free Modern URL Shortener.

其实是一个开源的自托管网址缩短工具,对于需要短网址的地方非常有用

配置

docker-compose.yml

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
version: "3"

services:
kutt:
image: kutt/kutt
depends_on:
- postgres
- redis
command: ["./wait-for-it.sh", "postgres:5432", "--", "npm", "start"]
ports:
- "3000:3000"
env_file:
- .env
environment:
DB_HOST: postgres
DB_NAME: kutt
DB_USER: user
DB_PASSWORD: pass
REDIS_HOST: redis

redis:
image: redis:6.0-alpine
volumes:
- ./redis:/data

postgres:
image: postgres:12-alpine
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: kutt
volumes:
- ./postgre:/var/lib/postgresql/data

.env

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
# App port to run on
PORT=3000

# The name of the site where Kutt is hosted
SITE_NAME="短网址工具-Kutt"

# The domain that this website is on
DEFAULT_DOMAIN=s.chowrex.com

# Generated link length
LINK_LENGTH=6

# Postgres database credential details
DB_HOST=postgres
DB_PORT=5432
DB_NAME=postgres
DB_USER=user
# Disable registration
DISALLOW_REGISTRATION=false

# Disable anonymous link creation
DISALLOW_ANONYMOUS_LINKS=false

# The daily limit for each user
USER_LIMIT_PER_DAY=50

# Create a cooldown for non-logged in users in minutes
# Set 0 to disable
NON_USER_COOLDOWN=10

# Max number of visits for each link to have detailed stats
DEFAULT_MAX_STATS_PER_LINK=5000

# Use HTTPS for links with custom domain
CUSTOM_DOMAIN_USE_HTTPS=true

# A passphrase to encrypt JWT. Use a long and secure key.
JWT_SECRET=jwttokensecret

# Admin emails so they can access admin actions on settings page
# Comma seperated
ADMIN_EMAILS=879582094@qq.com

# Invisible reCaptcha secret key
# Create one in https://www.google.com/recaptcha/intro/
RECAPTCHA_SITE_KEY=
RECAPTCHA_SECRET_KEY=

# Google Cloud API to prevent from users from submitting malware URLs.
# Get it from https://developers.google.com/safe-browsing/v4/get-started
GOOGLE_SAFE_BROWSING_KEY=

# Your email host details to use to send verification emails.
# More info on http://nodemailer.com/
# Mail from example "Kutt <support@kutt.it>". Leave empty to use MAIL_USER
MAIL_HOST=smtp.qq.com
MAIL_PORT=465
MAIL_SECURE=true
MAIL_USER=879582094@qq.com
MAIL_FROM=879582094@qq.com
MAIL_PASSWORD=yourcredencial

# The email address that will receive submitted reports.
REPORT_EMAIL=879582094@qq.com

# Support email to show on the app
CONTACT_EMAIL=879582094@qq.com

如果和我一样使用了 QQ 邮箱,注意 MAIL_USERMAIL_FROM 都需要输入 QQ 邮箱的地址,QQ 不支持 修改 From,否则邮件无法发出!会一直提示 ==An error occurred.==

Q&A

使用 Nginx 反向代理后,一致无限重定向

见Issue: Reverse Proxy Setup doesn't work · Issue #617 · thedevs-network/kutt · 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
42
server {
listen 443 ssl http2;
server_name s.chowrex.com;

# access_log /var/log/nginx/s.chowrex.com.access.log main;
keepalive_timeout 60;

# 证书路径,根据实际情况改写
ssl_certificate ssl/chowrex.com.cer;
ssl_certificate_key ssl/chowrex.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
# 禁止在header中出现服务器版本,防止黑客利用版本漏洞攻击
server_tokens off;

location / {
proxy_pass http://localhost:3000/;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}

}

server {
listen 80;
server_name s.chowrex.com;
# 禁止在header中出现服务器版本,防止黑客利用版本漏洞攻击
server_tokens off;
return 301 https://$host$request_uri;
}