【发布时间】:2019-02-27 23:34:20
【问题描述】:
我正在使用 VueJS 开发 SPA,它应该在远程域上使用 PHP API/Nginx 运行。当然,我遇到了 CORS 问题。
这是最近的 Nginx 配置文件:
location / {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, HEAD';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,some_my_tokens';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Max-Age' '1728000';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Origin,Content-Type,Accept,Authorization,some_my_tokens';
add_header 'Content-Type' 'text/plain; charset=UTF-8';
add_header 'Content-Length' '0';
return 204;
}
try_files $uri $uri/ /index.php?$args;
}
我仍然收到错误消息“请求的资源上没有 'Access-Control-Allow-Origin' 标头。因此不允许访问 Origin 'http://remote_host:8080'。”。
请帮忙。
【问题讨论】: