好久没更新博客了,现在毕设答辩也结束了,终于有时间更新一下了。今天先写写 Bitwarden 服务器吧。
Bitwarden就不多介绍了,很有名的开源密码管理器。Bitwarden 官方是有免费版的,也基本够用,但是既然有台服务器,又有些担心安全问题,就自己搭建了一个。
Bitwarden 官方也提供部署脚本和 Dokcer 镜像,但是占的资源比较多,所以选择了使用比较多的第三方的vaultwarden(原名 bitwarden_rs),非常轻量。
我是用 Doceker Compose,没什么难度,简单分享下 compose 文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| version: "3" services: vaultwarden: image: vaultwarden/server:latest container_name: vaultwarden restart: always environment: - LOG_FILE=/data/bitwarden.log - WEBSOCKET_ENABLED=true - TZ=Asia/Shanghai - LC_ALL=zh_CN.UTF-8 volumes: - /var/bitwarden/data/:/data/ ports: - 8880:80 - 3012:3012
|
然后用 Nginx 做了个反代,加了 SSL。
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
| upstream vaultwarden-default { server 127.0.0.1:8880; } upstream vaultwarden-ws { server 127.0.0.1:3012; } server { listen 80; listen [::]:80; server_name bitwarden.meancoder.xyz;
error_log /var/log/nginx/error.log;
return 301 https://$host$request_uri;
} server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name bitwarden.meancoder.xyz;
error_log /var/log/nginx/error.log;
ssl_certificate /home/ubuntu/.keys/bitwarden.meancoder.xyz/Nginx/1_bitwarden.meancoder.xyz_bundle.crt; ssl_certificate_key /home/ubuntu/.keys/bitwarden.meancoder.xyz/Nginx/2_bitwarden.meancoder.xyz.key;
location / { proxy_pass http://vaultwarden-default; 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 /notifications/hub { proxy_pass http://vaultwarden-ws; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }
location /notifications/hub/negotiate { proxy_pass http://vaultwarden-default; }
location /admin { auth_basic "Administrator’s Area"; auth_basic_user_file /etc/apache2/.htpasswd; 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_pass http://vaultwarden-default; } }
|
中间还遇到了一个小问题,刚搭建完的时候,想随便建个账号测试下,可是注册的时候一直报错,改了半天配置都不行。最后换了个复杂的密码就好了。