简体   繁体   English

node.js实时聊天服务器

[英]node.js real time chat server

hey guys i made chat for my chat application on my local host with some guids i found on the internet and im struggling to add is to my real server on line, now it listening to port localhost:3000 but i dont know what sould i do for a real server, help me please! 嗨,大家好,我在本地主机上使用我在互联网上找到的一些向导为我的聊天应用程序进行了聊天,我努力将其添加到我的真实服务器上,现在它正在监听端口localhost:3000,但我不知道我该怎么做对于真正的服务器,请帮帮我!

var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);

server.listen(process.env.PORT || 3000);
app.get('/',function(req,res){
   res.sendFile(__dirname + '/index.html');
});

Now you're gonna need to set up your server. 现在您将需要设置服务器。 I recommend digitalocean for a cheap cloud VPS. 我建议使用Digitalocean以获得便宜的云VPS。 You can follow this tutorial. 您可以按照本教程进行操作。

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04 https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

Basically you'll need to set up a process manager. 基本上,您需要设置一个流程管理器。 For node i recommend PS2. 对于节点,我建议使用PS2。

If you're looking to host your chat server from your residence, you will need to route external node traffic to the machine (or VM) which runs your node server. 如果您希望从自己的住所托管聊天服务器,则需要将外部节点流量路由到运行节点服务器的计算机 (或VM)。

You can do this by port forwarding . 您可以通过端口转发来实现 That means you'll need to go into your router's UI/settings panel and create a new port forwarding rule. 这意味着您需要进入路由器的UI /设置面板并创建新的端口转发规则。 Namely, you will probably want external traffic which arrives on port 80 to route to the local IP of your node server's machine on port 3000 . 也就是说,您可能希望外部通信通过端口80到达端口3000上节点服务器计算机的本地IP

Once this is done and the changes have been saved to your router config, you should already be able to put your public IP in a browser's URL bar and be directed to your web-facing node app. 完成此操作并将更改保存到路由器配置后,您应该已经可以将公共IP放在浏览器的URL栏中,并定向到面向Web的节点应用程序。

Beyond the scope of this question is getting yourself a domain name, and attaching it to your public IP, either statically or dynamically depending on your needs. 除了这个问题的范围之外,您还可以获取一个域名,然后根据需要将其静态或动态地附加到您的公共IP上。 That way, you wouldn't have to enter your public IP in the URL bar, you would just have to enter your domain, ie myfirstchatapp.com 这样,您不必在URL栏中输入公共IP,而只需输入您的域,即myfirstchatapp.com

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

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