Skip to content

Instantly share code, notes, and snippets.

@tiancheng91
Created April 5, 2018 16:35
Show Gist options
  • Save tiancheng91/d98413d1c7c2a6e7e9e5436eed4c475d to your computer and use it in GitHub Desktop.
Save tiancheng91/d98413d1c7c2a6e7e9e5436eed4c475d to your computer and use it in GitHub Desktop.
跨域配置
# find location in server section
location / {
# add the following, to enable CORS
# CORS OPTIONS
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Headers' 'Range' always;
add_header 'Access-Control-Allow-Methods' 'GET, HEAD, OPTIONS' always;
add_header 'Content-Length' 0;
return 204;
}
# CORS HEAD
if ($request_method = 'HEAD') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length' always;
}
# CORS GET
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length, Content-Range' always;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment