配置nginx

location / {
    index index.php;
    if ($request_method = 'OPTIONS') {
        add_header Access-Control-Allow-Origin '*';
        add_header Access-Control-Allow-Headers '*';
        add_header Content-Length 0;
        return 204;
    }
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?s=$1 last;
    }
}

配置php

public/index.php添加

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Access-Control-Request-Method: GET,POST,OPTIONS");

一般情况下根据需要放行所需域名、头部、请求类型即可

版权声明:本文为jlYang's Blog原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/yangjiale/p/16566679.html