FastAdmin 关于跨域问题解决
之前很久之前收集到社区的问题。 https://forum.fastadmin.net/thread/277
今天又有人问到,无法打开,估计是网络问题。
以下为完整配置 ^1
1# 2# CORS header support 3# 4# One way to use this is by placing it into a file called "cors_support" 5# under your Nginx configuration directory and placing the following 6# statement inside your **location** block(s): 7# 8# include cors_support; 9# 10# As of Nginx 1.7.5, add_header supports an "always" parameter which 11# allows CORS to work if the backend returns 4xx or 5xx status code. 12# 13# For more information on CORS, please see: http://enable-cors.org/ 14# Forked from this Gist: https://gist.github.com/michiel/1064640 15# 16 17set $cors ''; 18if ($http_origin ~ '^https?://(localhost|www\.yourdomain\.com|www\.yourotherdomain\.com)') { 19 set $cors 'true'; 20} 21 22if ($cors = 'true') { 23 add_header 'Access-Control-Allow-Origin' "$http_origin" always; 24 add_header 'Access-Control-Allow-Credentials' 'true' always; 25 add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; 26 add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always; 27 # required to be able to read Authorization header in frontend 28 #add_header 'Access-Control-Expose-Headers' 'Authorization' always; 29} 30 31if ($request_method = 'OPTIONS') { 32 # Tell client that this pre-flight info is valid for 20 days 33 add_header 'Access-Control-Max-Age' 1728000; 34 add_header 'Content-Type' 'text/plain charset=UTF-8'; 35 add_header 'Content-Length' 0; 36 return 204; 37}