也就是只是点击这个目录的时候需要密码,但是直连目录下的文件不需要密码
比如访问 https://drive.swo.moe/zh-CN/Shared%20files/的时候需要密码,但是直连 https://drive.swo.moe/api/raw/?path=/Shared%20files/genshin-impact-npc-scene-interaction.mp4 不需要密码.
是不是不大可能,由于服务在 serverless 上,不大好操作哈,不知道 nginx 或者 cloudflare 可以实现吗? 有大佬愿意的话,收费也可以哈
感谢
1
kaedeair 2023-01-30 09:52:45 +08:00 1
可以搞一个摘要认证的中间件,通过匹配路径来重定向,认证完毕再转回去,之前用 traefik 搭建 htpc 的时候实现过
|
2
cosmain 2023-01-30 10:01:20 +08:00 1
nginx 的 location 配置+http basic authentication
|
5
killva4624 2023-01-30 10:17:59 +08:00 1
location ~ ^/folder/\S+
{ ... # Process with files } location ~ ^/folder { .... # Process with auth # auth_basic "Administrator Login"; # auth_basic_user_file /other_folder/.htpasswd; } |
8
jsjcjsjc OP @killva4624 感谢,后面两个 location 是不是有问题哈~~
``` location / { proxy_ssl_name drive.swo.moe; proxy_ssl_server_name on; proxy_redirect off; proxy_pass https://drive.swo.moe; proxy_set_header Host drive.swo.moe; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cookie_domain drive.swo.moe test.domain.com; # proxy_set_header User-Agent $http_user_agent; proxy_set_header Referer drive.swo.moe; proxy_set_header Accept-Encoding ""; sub_filter 'drive.swo.moe' 'test.domain.com'; sub_filter_once off; } location ~ ^/Shared files/\S+ { proxy_pass https://drive.swo.moe/Shared files; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location ~ ^/Shared files { proxy_pass https://drive.swo.moe/Shared files; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; auth_basic "Administrator Login"; auth_basic_user_file /var/.htpasswd; } ``` |
9
killva4624 2023-02-01 10:58:42 +08:00 1
@jsjcjsjc 你这里的目录有空格,需要双引号吧...
|
10
jsjcjsjc OP |
11
killva4624 2023-02-02 10:13:36 +08:00 1
先去掉其他因素调试:
- 用不带空格的目录名; - proxy_pass 改成本地文件目录(root 或者 alias ,可以打开 debug 日志看最后访问的实际目录); 然后 location 换成实际目录,正常后再改成 proxy_pass 。 |
12
jsjcjsjc OP @killva4624 再次感谢,似乎问题出在这里,这样写好像是不规范的.
``` location ~ ^/Shared/\S+ { proxy_pass https://drive.swo.moe/Shared; } ``` 会报错 ``` nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /www/server/panel/vhost/nginx/test.1ka.net.conf:55 nginx: configuration file /www/server/nginx/conf/nginx.conf test failed ``` |