20 次浏览
在树莓派5 + OMV (OpenMediaVault) 环境下,用 Nginx + Let’s Encrypt 为 OMV Web 管理界面添加 SSL证书,实现HTTPS访问。
1、前提条件
请确保以下环境准备好:
OMV 已安装并运行(访问地址如 http://Raspberry.local:80)。
树莓派有公网访问能力(或至少可通过公网域名访问到树莓派的80、443端口)。
你有一个已解析到树莓派公网IP的域名(如 nas.example.com)。
2、安装依赖与准备证书
安装 Certbot
sudo apt update
sudo apt install certbot python3-certbot-nginx -y
申请 Let’s Encrypt 证书
sudo certbot certonly --nginx -d nas.example.com
然后按提示输入邮箱、同意协议。
成功后证书会保存在:
/etc/letsencrypt/live/nas.example.com/fullchain.pem
/etc/letsencrypt/live/nas.example.com/privkey.pem
如果无法使用 80 端口(例如家庭宽带屏蔽),可使用 DNS 验证模式:
sudo certbot certonly --manual --preferred-challenges dns -d nas.example.com
按提示在域名 DNS 中添加 TXT 记录验证。
3、配置 Nginx 反代 OMV
创建 Nginx 配置文件
sudo nano /etc/nginx/conf.d/omv-ssl.conf
配置内容如下:
server {
listen 80;
server_name nas.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name nas.example.com;
ssl_certificate /etc/letsencrypt/live/nas.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/nas.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://127.0.0.1:80; # OMV 默认运行在80端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
测试并启动配置
sudo nginx -t
sudo systemctl restart nginx
4、SSL证书自动续期
Let’s Encrypt 证书有效期 90 天,建议添加自动续期任务:
sudo crontab -e
添加一行:
0 3 * * * certbot renew --quiet && systemctl reload nginx
每天凌晨3点自动检查并续期。