【问题标题】:node.js on elastic beanstalk: firefox 502 bad gateway弹性beantalk上的node.js:firefox 502 bad gateway
【发布时间】:2015-02-07 19:54:28
【问题描述】:

我在 aws elastic 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();
});

有什么想法吗?

【问题讨论】:

  • 我在尝试使用 ajax 上传照片时遇到了同样的问题。它适用于本地,但不适用于 aws beanstalk。如果你有任何发现,请分享

标签: node.js amazon-elastic-beanstalk


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    • 2019-12-15
    • 2020-04-05
    • 2020-07-12
    • 2023-03-20
    • 2023-03-04
    相关资源
    最近更新 更多