跨域问题解决

1.在web服务器上直接配置

例子:nginx 配置

1.https://www.cnblogs.com/itzgr/p/13343387.html 有详细说明

2.配置例子:

 1 location ~ \.php(.*)$ {
 2             fastcgi_pass   127.0.0.1:9003;
 3             fastcgi_index  index.php;
 4             fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
 5             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 6             fastcgi_param  PATH_INFO  $fastcgi_path_info;
 7             fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
 8             include        fastcgi_params;
 9             if ($request_method = 'OPTIONS') {
10         add_header 'Access-Control-Allow-Origin' '*' always;
11         add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE' always;
12         add_header 'Access-Control-Allow-Headers' '*' always;
13         add_header 'Access-Control-Max-Age' 1728000 always;
14         add_header 'Content-Length' 0;
15         add_header 'Content-Type' 'text/plain; charset=utf-8';
16         return 204;
17     }
18 
19     if ($request_method ~* '(GET|POST|DELETE|PUT)') {
20         add_header 'Access-Control-Allow-Origin' '*' always;
21     }
22 }

 

posted @ 2021-06-07 11:39  kaycn  阅读(42)  评论(0)    收藏  举报