简体   繁体   中英

How to deploy my node server to the internet from local host

I have a ubuntu18 machine in which I have developed a webapplication.

The web application has a front-end(HTML,CSS and Javascript) and a back-end(Nodejs,python,java). The front-end and the back-end communicates via websocket. The back-end consists of two servers one runs on Nodejs and another one runs on java.

when I test the application on my localhost everything works fine. I want to use my public ip address to let anyone on internet access this application. I don't have a domain name now.

How can I make my back-end server running on my ubuntu machine available for websocket connection from anywhere in the world??

Detailed explanation is appreciated as I am a newbie to this field.

There are different npm modules available in order to provide a domain name and eventually providing an ability to access your local server from outside world. Having said that in your local if the server gets stopped, then again you might have to generate a new domain name and share it across. There are other approaches in mitigating this as well.

But what I understand from your question is this is the answer you are looking for. . Hope this helps.

To expose a server running locally on your computer, you need to allow access to your network on the correct port, which means letting your router know what to do when it receives web traffic to a certain port, which is most likely closed by default.

Although this may not be the safest solution to a large scale project, it is generally how you host most servers, including HTTP servers, game servers, etc, and in order to achieve this you must port forward your router.

Port Forwarding

To let your router know how to act when it receives traffic directed to a certain port, you must access its configurations through the gateway. It is advised to look for your specific router model online for a quick and easy guide, but generally this is how it goes:

  1. Open your browser and navigate to your router's gateway to access the configuration page (usually 192.168.1.1 ).
  2. Login using the administrator credentials. If you never did this they are probably the default credentials, google the router's model to find out. This list may help you .
  3. Navigate to a section called Port Forwarding , usually it falls below advanced configurations or the firewall section.
  4. You want to setup a new forwarding rule according to the port your server listens on, and the local IPv4 address of your machine, for instance, if your server listens on port 1337 and your local IP address is 192.168.1.120 , you should set up both TCP and UDP rules, and this essentially lets your router know that any traffic incoming to that specific port will be redirected to your machine (this step may vary a lot depending on your router's manufacturer)
  5. Last but not least, your local machine should be running on a static IP (192.168.1.XXX), to make sure it doesn't change automatically. To do this in Ubuntu / other distros, please refer to this guide .

After port forwarding your router, the server should be available through your external IP address ( Use this to easily find out what your external IP is , and the port you defined, for example: 264.186.45.7:1337 .

Custom Hostname

To use a custom DNS resolver in order to have a customized URL for your server, you can use free tools like noip , which have a good choice of free hostnames for your server. All you need is to setup a hostname and download their client that automatically reroutes all your server's traffic to that external URL, so instead of an IP address, you may have a nice hostname like awesome-server.ddns.net .

Conclusion

This is not a very in-depth guide, just a quick rundown of the steps necessary to expose a local server to the outside world, so for each step some amount of research is required. If you need any further help or want to point something out, feel free to edit the answer or leave a comment down below.

One thing you could do that doesn't need port forwarding from the router is tunneling which works the same way

Try Using ngrok( https://ngrok.com/ ) it doesnt need port forwarding, download ngrok and run ngrok.exe tcp 5001 5001 is the port to portward and tcp is the protocol(http, tcp, ..), to connect to it online use the "Forwarding" which will be something like 4.tcp.ngrok.io:4869 which will forward to localhost port 5001

NOTE: you can use it without an account but it will expire every 7 Hours, view the to use account read https://dashboard.ngrok.com/auth/your-authtoken (after creating an account)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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