我正在尝试使用 ngnix 代理 node.js 服务器。我的问题是我无法访问(curl 或 nginx)本地主机上的 node.js 服务器,
当它的 3000 端口对外开放时,我可以看到我的节点 js 服务器正在运行。但是 curl 和 nginx 无法访问它。
一件奇怪的事情是我们启动了一个 mongodb,并且可以在 localhost 上访问它而没有任何问题
我的实例 ID 如下: i-0fef394cbc350a4f4
这是找不到本地主机并因此超时的 nginx 服务器的链接:http: //ec2-54-246-136-64.eu-west-1.compute.amazonaws.com/
我找不到另一种方法来证明我们无法访问 curl localhost:3000
var sticky = require("socketio-sticky-session");
sticky(function () {
// This code will be executed only in slave workers
var http = require('http');
var socketIO = require('socket.io');
var server = http.createServer(app);
var io = socketIO(server);
require('./app_api/config/socketio')(io);
io.on('connection', (socket) => {
log.trace("new user connected");
socket.on('disconnect', () => {
log.trace("user disconnected");
});
});
connectToDispatcher();
process.title = "share_place";
return server;
}).listen(3000, function () {
console.log((cluster.worker ? 'WORKER ' + cluster.worker.id : 'MASTER') + '| PORT ' + 3000)
app.domain.on('error', (er) => {
log.error('error', er.stack);
try {
// make sure we close down within 30 seconds
var killtimer = setTimeout(() => {
process.exit(1);
}, 30000);
// But don't keep the process open just for that!
killtimer.unref();
// stop taking new requests.
server.close();
// Let the master know we're dead. This will trigger a
// 'disconnect' in the cluster master, and then it will fork
// a new worker.
cluster.worker.disconnect();
// try to send an error to the request that triggered the problem
res.statusCode = 500;
res.setHeader('content-type', 'text/plain');
res.end('Oops, there was a problem!\n');
} catch (er2) {
// oh well, not much we can do at this point.
log.error('Error sending 500!', er2.stack);
}
});
}
);
一个更奇怪的情况:我们在 beanstalk 实例上安装了节点代码。
我们从外部访问节点服务器:http ://share-place.eu-west-1.elasticbeanstalk.com:8081/
但是来自亚马逊的默认 nginx 会回复一条连接被拒绝的消息(对于我们可以从外部访问的公共资源)
/var/log/nginx/error.log
2017/04/21 14:32:19 [警告] 3360#0:在 /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf:42 中重复 MIME 类型“text/html”:42 2017/04/21 14:37:48 [警告] 7358#0:在 /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf:42 2017/04/21 14:38:41 中重复 MIME 类型“text/html” [错误] 7362#0: *1 连接() 连接到上游时失败(111:连接被拒绝),客户端:41.226.2.5,服务器:,请求:“GET / HTTP/1.1”,上游:“ http://127.0.0.1:8081/ ”,主机: “share-place.eu-west-1.elasticbeanstalk.com” 2017/04/21 14:38:41 [错误] 7362#0: *1 连接()失败(111:连接被拒绝)同时连接到上游,客户端:41.226.2.5,服务器:,请求:“GET /favicon.ico HTTP/1.1”,上游:“ http://127.0.0.1:8081/favicon.ico ”,主机:“share-place.eu-west-1.elasticbeanstalk.com”,推荐人:“http://share-place.eu-west-1.elasticbeanstalk.com/ " 2017/04/21 14:38:45 [错误] 7362#0: *1 connect() failed (111: Connection refused) while connection到上游,客户端:41.226.2.5,服务器:,请求:“GET / HTTP/1.1”,上游:“ http://127.0.0.1:8081/ ”,主机:“share-place.eu-west-1。 elasticbeanstalk.com"