【发布时间】: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