【发布时间】:2018-05-09 08:39:16
【问题描述】:
我正在使用 nodejs 的服务器上工作,该服务器在我租用的 VPS 上运行。从我电脑上的本地主机,我向服务器发送了一个请求,但它给我的只是:
请求的资源上不存在“Access-Control-Allow-Origin”标头。 Origin 'http://localhost:8086' 因此不允许访问。
但我在 de Nginx 配置的默认文件中有这个:
location / {
proxy_set_header 'Access-Control-Allow-Origin' '*';
proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
proxy_set_header 'Access-Control-Allow-Headers' 'X-Requested-With,Accept,Content-Type, Origin';
proxy_pass http://localhost:8080;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
这里有一个 Access-Control-Allow-Origin 标头,所以这里有什么问题。
一如既往地感谢您的帮助!
【问题讨论】:
-
您的节点服务器是否处理
options请求?如果不是,则您正在传递请求,然后被节点服务器拒绝
标签: node.js nginx http-headers cors