欢迎登录

跨资源请求CORS和nginx代理

:2019-12-16    :184 次   :791 字   

前言:

实现后端跨域请求,php后端使用

代码:

php后端跨域

    header('Content-Type:application/json; charset=utf-8');
    header('Access-Control-Allow-Origin:http://localhost:8080'); // *代表允许任何网址请求
    header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); // 允许请求的类型
    header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
    header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin'); // 设置允许自定义请求头的字段

nginx代理

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
    暂无评论,快来抢沙发吧!
×