簡體   English   中英

如何為Digital Ocean部署設置NodeJS + Socket.io

[英]How to setup NodeJS + Socket.io for Digital Ocean deployment

我正在試圖弄清楚如何在Digital Ocean中部署我的節點應用程序。 它在我的本地機器上工作正常。

我按照教程如何操作並使用該教程中的示例,我能夠使用pm2 start filename.js訪問該站點

123.45.6.78 =數字海洋IP地址

 var http = require('http');
 http.createServer(function (req, res) {
   res.writeHead(200, {'Content-Type': 'text/plain'});
   res.end('Hello World\n');
 }).listen(8080, '123.45.6.78');
 console.log('Server running at http://123.45.6.78:8080/');

在我的真實應用程序上,我試圖像上面的示例一樣模式化它,並使用pm2 start filename.js

var os = require('os');
var nodeStatic = require('node-static');
var http = require('http');
var socketIO = require('socket.io');

var fileServer = new(nodeStatic.Server)();
var app = http.createServer(function(req, res) {
   fileServer.serve(req, res);
}).listen(8080, '123.45.6.78');

var io = socketIO.listen(app);

結果是This site can't be reached 123.45.6.78 refused to connect.

謝謝你的幫助。

寫只聽(8080,'127.0.0.1');

數字海洋默認關閉所有端口,除了:80

我已經在這里回答了這個問題

https://stackoverflow.com/a/41408983/4556995

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM