加载中

PHP跨域设置

配置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");

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

posted @ 2022-08-09 16:50  jialeYang  阅读(944)  评论(0编辑  收藏  举报