使用 1Panel 为 qBittorrent 配置 HTTPS 后,首页能打开,但 CSS、JS 和图片全部返回 401。
原因
访问地址使用了非标准端口:
https://qb.example.com:9443/1Panel 反代时若使用 $host,可能会丢失 :9443:
Host: qb.example.com
Referer: https://qb.example.com:9443/qBittorrent 检测到 Host 与 Referer 不一致,触发 CSRF 防护并返回 401。
解决方法
在反向代理配置中加入:
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;关键是使用:
proxy_set_header Host $http_host;$http_host 会保留 :9443,而 $host 可能丢失端口。
保存并重载 Nginx/OpenResty,再清除浏览器缓存即可。不要长期关闭 qBittorrent 的 Host 或 CSRF 校验。