nginx配置转发带请求头

nginx配置转发带请求头

如果发现数据还是没有正确的携带过去,那就要添加

允许带下划线的 Header​

underscores_in_headers on;

location /api/open/ {
    proxy_pass https://www.chanjing.cc/api/open/;
    
    # 添加或修改这些配置
    proxy_set_header Host www.chanjing.cc;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    
    # 重要:确保 access_token 请求头被正确传递
    proxy_set_header access_token $http_access_token;
    proxy_set_header access-Token $http_access_token;
    proxy_set_header Authorization "Bearer $http_access_token";
    
    # 其他必要的 CORS 相关配置
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,access_token';
    
    # 处理 OPTIONS 请求
    if ($request_method = 'OPTIONS') {
        return 204;
    }
}
温馨提示: 本文最后更新于2025-06-23 16:46:43,某些文章具有时效性,若有错误或已失效,请在下方 留言
© 版权声明
THE END
喜欢就支持一下吧
点赞9赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容