【发布时间】:2014-06-22 02:36:45
【问题描述】:
无法理解为什么我的上游/CORS 配置失败。这会阻止一些本地开发和测试。
从 local.mysite.com:8081 发出 API 请求时,我收到 请求的资源上没有“Access-Control-Allow-Origin”标头 strong> 到 events.mysite.com。
这是我来自 /etc/nginx/sites-available/mysite 的服务器配置
# the IP(s) on which your node server is running. I chose port 3000.
upstream mysite {
server 127.0.0.1:3000;
}
# the nginx server instance
server {
listen 0.0.0.0:80;
server_name mysite events.mysite.com;
access_log /var/log/nginx/mysite.log;
# pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
location / {
proxy_set_header Access-Control-Allow-Origin *;
# proxy_set_header 'Access-Control-Allow-Credentials' 'true'; # i've tried with and without this setting
proxy_set_header 'Access-Control-Allow-Headers' 'X-Requested-With,Accept,Content-Type, Origin';
proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_mysite/;
proxy_redirect off;
}
}
也,我尝试在 Access-Control-* 选项上使用 add_header 而不是 proxy_set_header,但也没有骰子。
我正在运行一个 Node.js 应用程序。我没有修改 Node 代码来处理 CORS...是我的 nginx 配置错误,还是没问题,但我需要在 Node 中执行其他操作?
【问题讨论】: