alist icon indicating copy to clipboard operation
alist copied to clipboard

使用https访问时,下载按钮仍然是http协议

Open Windman1320 opened this issue 2 years ago • 1 comments

Please make sure of the following things

  • [X] I have read the documentation.
  • [X] I'm sure there are no duplicate issues or discussions.
  • [X] I'm sure it's due to alist and not something else(such as Dependencies or Operational).
  • [X] I'm sure I'm using the latest version

Alist Version / Alist 版本

V3.3.0

Driver used / 使用的存储驱动

WebDav

Describe the bug / 问题描述

环境: 已配置nginx反向代理,配置了ssl,外网通过https访问网页,端口为非默认(80或者443) 问题: 在文件下载界面,下载按钮后面url为http协议导致跳转到http下载失败,临时解决方案为监听http的此端口并再次重定向 补充:config文件site_url未配置(已测试如果配置为https的域名,则外网使用非默认端口访问请求api/public/settings会404)

Reproduction / 复现链接

见下方贴图

Logs / 日志

下载按钮: Snipaste_2022-11-06_23-08-06 config配置文件: Snipaste_2022-11-06_23-13-22

Windman1320 avatar Nov 06 '22 15:11 Windman1320

Thanks for opening your first issue here! Be sure to follow the issue template!

welcome[bot] avatar Nov 06 '22 15:11 welcome[bot]

反向代理时后端无法识别当前使用的protocol 要https 只能手动填写site_url。

xhofe avatar Nov 07 '22 03:11 xhofe

Hello @Windman1320, your issue is invalid and will be closed. 你好 @Windman1320,你的issue无效,将被关闭。

github-actions[bot] avatar Nov 07 '22 03:11 github-actions[bot]

反向代理时后端无法识别当前使用的protocol 要https 只能手动填写site_url。

但是手动填写site_url(https://+域名,不带端口号)后,我无法通过非443端口正常访问网站了,api请求直接拿site_url的地址,没有带访问时的端口号,能否有一种方式,可以指定site_url的时候也携带访问网页的端口去请求api

Windman1320 avatar Nov 07 '22 13:11 Windman1320

反向代理时后端无法识别当前使用的protocol 要https 只能手动填写site_url。

但是手动填写site_url(https://+域名,不带端口号)后,我无法通过非443端口正常访问网站了,api请求直接拿site_url的地址,没有带访问时的端口号,能否有一种方式,可以指定site_url的时候也携带访问网页的端口去请求api

听不懂你在说什么 Demo站设置了site_url 无任何问题。

xhofe avatar Nov 07 '22 16:11 xhofe

反向代理时后端无法识别当前使用的protocol 要https 只能手动填写site_url。

但是手动填写site_url(https://+域名,不带端口号)后,我无法通过非443端口正常访问网站了,api请求直接拿site_url的地址,没有带访问时的端口号,能否有一种方式,可以指定site_url的时候也携带访问网页的端口去请求api

听不懂你在说什么 Demo站设置了site_url 无任何问题。

demo站点是用的默认端口,我的问题是使用非默认端口时,api请求的仍然是默认端口

Windman1320 avatar Nov 08 '22 05:11 Windman1320

提供reproduction 并详细说明问题。

xhofe avatar Nov 08 '22 05:11 xhofe

提供reproduction 并详细说明问题。

Reproduction config.json配置,site_url为https://test.windmancloud.com:

{
  "force": false,
  "address": "0.0.0.0",
  "port": 5244,
  "site_url": "https://test.windmancloud.com",
  "cdn": "",
  "jwt_secret": "xxxx",
  "token_expires_in": 48,
  "database": {
    "type": "sqlite3",
    "host": "",
    "port": 0,
    "user": "",
    "password": "",
    "name": "",
    "db_file": "data/data.db",
    "table_prefix": "x_",
    "ssl_mode": ""
  },
  "scheme": {
    "https": false,
    "cert_file": "",
    "key_file": ""
  },
  "temp_dir": "data/temp",
  "log": {
    "enable": true,
    "name": "log/log.log",
    "max_size": 10,
    "max_backups": 5,
    "max_age": 28,
    "compress": false
  }
}

复现链接:https://test.windmancloud.com:8443/

现象:页面能够访问,提示Failed fetching settings: Network Error,F12查看api请求地址为https://test.windmancloud.com/api/public/settings 111

预期:通过8443端口访问时,api请求地址也携带端口号(该问题在不指定site_url时不会发生,但不指定的情况下文件下载链接又是http的,无法正常下载)

Windman1320 avatar Nov 08 '22 14:11 Windman1320

。。。你不使用443端口 site_url当然也需要携带你用的端口

xhofe avatar Nov 08 '22 14:11 xhofe

。。。你不使用443端口 site_url当然也需要携带你用的端口

啊这,那我内网下没法用443了啊

Windman1320 avatar Nov 08 '22 14:11 Windman1320

有办法可以更改下载链接地址,让它的协议与访问协议一样不

Windman1320 avatar Nov 08 '22 14:11 Windman1320

自行修改源代码指定 源项目不考虑这种内外网使用不同端口的情况。

xhofe avatar Nov 08 '22 14:11 xhofe

能请教下思路不

Windman1320 avatar Nov 08 '22 14:11 Windman1320

https://github.com/alist-org/alist/blob/e05e2fd663b2527c97c508370b755488f358aff6/server/common/base.go#L18

xhofe avatar Nov 08 '22 14:11 xhofe

好的 感谢

Windman1320 avatar Nov 08 '22 14:11 Windman1320

https://github.com/alist-org/alist/blob/e05e2fd663b2527c97c508370b755488f358aff6/server/common/base.go#L19 请教一下,r.TLS什么时候不为空呢?是config开启https并配置证书后么

Windman1320 avatar Nov 08 '22 15:11 Windman1320

从v3.9.1开始 已支持通过X-Forwarded-Proto识别,需在反向代理时配置。

xhofe avatar Jan 20 '23 11:01 xhofe

从v3.9.1开始 已支持通过X-Forwarded-Proto识别,需在反向代理时配置。

感谢

Windman1320 avatar Jan 20 '23 12:01 Windman1320

我也遇到这个问题,但是从你们对话中,我找到 site_url 字段,并且修改为 "https://test.windmancloud.com:8443",可以正常下载了

ougato avatar Aug 09 '23 06:08 ougato

@ougato 反向代理设置X-Forwarded-Proto就可以了,site_url的方法有弊端,不适用于本地/公网IP不一样的场景

Windman1320 avatar Aug 10 '23 13:08 Windman1320

@Windman1320 感谢您的回答,我又跑来找这个问题的解决方案,你的方式是快速解决这个问题的方式,在nginx反向代理中设置:proxy_set_header X-Forwarded-Proto https;

ougato avatar Nov 09 '23 04:11 ougato

@Windman1320 谢谢大佬,好几天没解决的问题一句反代解决了

yanshuangchen avatar Apr 24 '24 13:04 yanshuangchen