You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无需Lua的Nginx多Cookie场景下auth_request替代方案咨询

无需Lua的Nginx多Cookie场景下auth_request替代方案咨询

大家好,我正在做基于Cookie的文件访问认证功能,一开始写了这样的Nginx配置:

location /private/ {
    auth_request     /auth;
    auth_request_set $auth_status $upstream_status;
    auth_request_set $saved_set_cookie $upstream_http_set_cookie;
    add_header Set-Cookie $saved_set_cookie;

    try_files $uri @pull_file;
}

location = /auth {
    internal;
    proxy_pass              https://127.0.0.1:443/Access/Get;
    proxy_pass_request_body off;
    proxy_set_header        Content-Length "";
    proxy_set_header        X-Original-Uri $request_uri;
}

先跟大家说明下try_files的作用:这是源站拉取CDN配置的一部分,如果请求的$uri在本地找不到,@pull_file会去上游拉取文件、存到对应路径后再返回给客户端,这部分目前运行完全正常。

现在遇到的情况是,/auth这个内部代理接口会返回多个Set-Cookie响应头,我目前是用$upstream_http_set_cookie来获取这些Cookie,再通过add_header把它们回传给客户端。但我总觉得这种处理多Cookie的方式不够优雅,而且可能存在一些潜在问题,想请教下有没有不需要依赖Lua脚本的替代方案,能更好地处理这种多Cookie的传递场景?

备注:内容来源于stack exchange,提问作者Lesotto

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 09:48:07