Skip to content

Instantly share code, notes, and snippets.

@xieyuschen
Last active December 28, 2020 13:54
Show Gist options
  • Save xieyuschen/02b1d21c1b13a16f06dcf789e7e7a4ec to your computer and use it in GitHub Desktop.
Save xieyuschen/02b1d21c1b13a16f06dcf789e7e7a4ec to your computer and use it in GitHub Desktop.
How nginx deal with a CORS request

Nginx处理跨域请求

在过去处理跨域问题上,只要在nginx中加入如下内容,就可以解决跨域的问题:

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

那么根据上篇文章,使用一个OPTIONS的方法就可以获取到一些跨域的内容, 然后浏览器经过预处理之后,就可以完成跨域的操作。这个经过实践应该来说是没有问题的,但写这个贴子希望可以稍微深入一点了解这个请求的内容是如何被nginx加上去的。

很棒的文章,写的很清晰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment