弹性beanstalk上的node.js:firefox 502坏的网关

我在aws弹性beanstalk上运行节点,一切都很好,直到我开始在浏览器中运行ajax请求时出现“502 Bad Gateway”。

检查日志我看到:

2014/12/09 18:56:48 [error] 25746#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 108.56.255.64, server: , request: "OPTIONS /match/update HTTP/1.1", upstream: "http://xxxx:8081/match/update", host: "xxxx.elasticbeanstalk.com" 2014/12/09 18:56:50 [error] 25746#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 108.56.255.64, server: , request: "POST /match/update HTTP/1.1", upstream: "http://xxxx:8081/match/update", host: "xxxx.elasticbeanstalk.com" 

我已经在node.js中实现了CORS,所以跨域请求应该是可以的:

 app.all('/', function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); }); 

有任何想法吗?

我发现我的问题。 我在网页的jQuery部分做了ajax调用,有一个document.write行。 这在本地运行时不会造成问题,但是在弹性beanstalk上运行时,有两个调用(一个用于OPTIONS,另一个用于POST),第一个ajax调用OPTIONS运行正常,但是document.write会中断POST,终止连接。 我花了整整一天的时间,我的问题是一个简单的document.write。 因此,请确保您的asynchronous进程可以在加载页面时运行完成。