Skip to content

HTTP 请求头中的 Authorization 字段未被允许 #130

@Dream4ever

Description

@Dream4ever

在将 API 程序由 Windows 迁移到 CentOS 并由 Nginx 进行反向代理之后,先后解决了 Nginx OPTIONS 请求 405 错误Nginx 不允许跨域请求 这两个问题,但是浏览器中访问的页面调用 API 时,又报下面的错误:

Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response

仔细看了一下报错信息,大意是说 HTTP 请求头中的 Authorization 字段未被允许。

上网搜索了一下报错信息 + nginx,按照链接 Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response. (nginx) 中的方法,在 if ($request_method = OPTIONS ) 配置段的 add_header Access-Control-Allow-Headers 这一行中,增加了 Authorization 字段,然后重启了 Nginx,总算解决问题了。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Back-endWhere data really come and goServerThe invisible hero

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions