简体   繁体   English

弹性beantalk上的node.js:Firefox 502错误网关

[英]node.js on elastic beanstalk: firefox 502 bad gateway

I'm running node on aws elastic beanstalk and everything was fine until I started getting a "502 Bad Gateway" when running an ajax request in a browser. 我在aws弹性beantalk上运行节点,一切都很好,直到在浏览器中运行ajax请求时开始获取“ 502 Bad Gateway”。

Checking the logs I see: 查看我看到的日志:

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"

I've implemented CORS in node.js so cross domain requests should be ok: 我已经在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();
});

Any ideas? 有任何想法吗?

I found my problem. 我发现了问题。 I had a document.write line in the jQuery portion of the web page making the ajax call. 我在进行ajax调用的网页的jQuery部分中有一个document.write行。 This didn't cause a problem when running locally, but when running on elastic beanstalk, there were two calls made (one for OPTIONS and the other the POST), the first ajax call OPTIONS runs ok, but the document.write would interrupt the POST, terminating the connection. 在本地运行时这不会引起问题,但是在弹性beantalk上运行时,有两个调用(一个用于OPTIONS,另一个用于POST),第一个ajax调用OPTIONS运行正常,但是document.write会中断POST,终止连接。 I spent the entire day on this and my problem was a simple document.write. 我花了一整天的时间,而我的问题是一个简单的document.write。 So make sure your async processes can run to completion when loading your page. 因此,请确保您的异步过程在加载页面时可以运行完毕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM