alist 默认的端口为 5244,为访问方便,一般都是通过反代进行访问,免去了输入端口号。
反向代理的程序有很多,官网文档上描述的有 nginx, apache, caddy等 web 程序,本文只讨论 nginx,并默认已配置好其他设置,只针对 location 配置块。
根目录反代 根目录反代是最为简单的,直接按照官方文档进行配置即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Range $http_range; proxy_set_header If-Range $http_if_range; proxy_redirect off ; proxy_pass http://127.0.0.1:5244; client_max_body_size 20000m ; proxy_http_version 1 .1 ; }
配置好后直接访问域名即可。比如 https://alist.example.com
子目录反代 想将程序反代至子目录,比如 https://alist/exampl.com/alist
这时就需要修改一些配置来实现该要求。
在 alist 的配置文件 data/config.json 中修改 site_url 配置
1 "site_url":"" ----> "site_url":"/alist"
根据自己的实际情况进行修改 site_url
nginx location 配置块如下所示
1 2 3 4 5 6 7 8 9 location /alist { proxy_pass http://127.0.0.1:5244; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Range $http_range; proxy_set_header If-Range $http_if_range; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; }
配置好后就可以通过 https://alist.example.com/alist 进行访问
问题及解决办法 问题:播放视频时地址栏出现不安全警告
通过打开控制台就可发现这个警告来源
1 Mixed Content: The page at 'https://alist.example.com/alist/test.mp4' was loaded over HTTPS, but requested an insecure element 'http://alist.example.com/alist/test.mp4'.
这是因为 https 页面加载了 http 资源,所以出现了警告
解决方法:在 site_url 配置项补全网址,比如
1 "site_url":"/alist" ---> "site_url":"https://alist.example.com/alist"