部署方式
选择在腾讯云服务器上部署思源笔记,最便捷的方式就是使用Docker部署,个人选择使用docker compose的方式进行部署,下面是docker-compose.yaml文件配置信息
version: "3.9"
services:
main:
image: b3log/siyuan
command: ['--workspace=/siyuan/workspace/', '--accessAuthCode=${AuthCode}']
ports:
- 6806:6806
volumes:
- /siyuan/workspace:/siyuan/workspace
restart: unless-stopped
environment:
# A list of time zone identifiers can be found at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
- TZ=${YOUR_TIME_ZONE}
- PUID=${YOUR_USER_PUID} # 自定义用户 ID
- PGID=${YOUR_USER_PGID} # 自定义组 ID
参数说明
-
--workspace=/siyuan/workspace/
: 指定笔记数据存储路径,保持默认即可 -
--accessAuthCode=${AuthCode}
: 设置访问授权码(重要!必须修改) -
6806:6806
: 将容器内服务的 6806 端口映射到宿主机同端口 -
数据卷挂载保证了笔记数据的持久化存储
-
环境变量需要配置时区、用户/组 ID(权限控制)
- 时区:
TZ=Asia/Shanghai
- 用户ID:使用
id -u
命令查看当前用户的ID - 用户组ID:使用
id -g
命令查看当前用户的用户组ID
- 时区:
实战配置
version: "3.9"
services:
main:
image: b3log/siyuan
command: ['--workspace=/siyuan/workspace/', '--accessAuthCode=123***456']
ports:
- 6806:6806
volumes:
- /home/docker/siyuan/workspace:/siyuan/workspace
restart: unless-stopped
environment:
# A list of time zone identifiers can be found at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
- TZ=Asia/Shanghai
- PUID=1005
- PGID=1005
配置域名与nginx代理
思源笔记在使用nginx进行代理时,WebSocket的服务必须进行配置
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name example.com www.example.com;
# 使用同一证书(需证书支持通配符或包含该子域名)
ssl_certificate /path/to/nginx/cacert/example.com.crt;
ssl_certificate_key /path/to/nginx/cacert/example.com.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:AES128+EECDH:AES256+EECDH';
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:6806;
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;
}
location /ws {
proxy_pass http://127.0.0.1:6806/ws;
proxy_http_version 1.1;
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;
}
}