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");
一般情况下根据需要放行所需域名、头部、请求类型即可