Nginx代理Nodejs(Dokku)。 CORS响应标题不通过

我正在使用Dokku在DigitalOcean上托pipe我的应用程序。 Dokku运行nginx 1.6来模拟类似Heroku的代理Docker应用程序。 该应用程序的所有共享类似的默认configuration,如下所示。

我的Node.js服务器使用CORS中间件告诉浏览器允许www.myapp.com打电话给api.myapp.com:

这在我的本地计算机上正常工作。 当我部署它,我在浏览器中得到一个CORS错误:

XMLHttpRequest cannot load https://api.myapp.com/r_u_up. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.myapp.com' is therefore not allowed access. The response had HTTP status code 502. 

所以,跆拳道,结束了。

我发现这个nginx CORSconfiguration,但它似乎非常crufty。 这是旧的代码,还是最好的方法? 这个插件使用该configuration。

我更喜欢简单的configuration,只是通过响应头。 我的应用程序不需要nginx来拦截它们。 我如何configuration?

应用程序的nginx.conf的:

 upstream www { server 172.17.0.135:5000; } server { listen [::]:80; listen 80; server_name www.myapp.com ; return 301 https://www.myapp.com$request_uri; } server { listen [::]:443 ssl spdy; listen 443 ssl spdy; server_name www.myapp.com; keepalive_timeout 70; add_header Alternate-Protocol 443:npn-spdy/2; location / { proxy_pass http://www; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header X-Request-Start $msec; } include /home/dokku/www/nginx.conf.d/*.conf; } 

更新:所以事实certificateCORS是一个僵尸行走死疯狂的规范,是的,这是与一个nginxconfiguration是最好的方法。

http://enable-cors.org/

nginx是最好的方式,nginx是最快和最接近客户端的过程。

如果nginx可以处理不接触你的应用程序(node.js,php,rails等)的请求,那么你的应用程序将会更容易扩展,运行更快。