简体   繁体   中英

How to create a local server without using ngrok?

I have been using NGRok as a server for my chatbot. So i want to create a local server using my static IP & Host that chatbot on it. Anyone knows how to do this?

This depends on the specifics of your chatbot. I assume that it behaves like a HTTP server.

You have to ensure that the following criteria apply:

  • Ensure that your server is also listening on your external interface, not only your local interface. On Linux you can for example use netstat -atulpen to check this. If your process is listed with state LISTEN and a local address of either :::<PORT> or 0.0.0.0:<PORT> , then it listens on all interfaces. If the local address is your external ip address, it is also fine! If you see something else here, check your code for the statement were you assign the port to your server. Here you can usually also set the host to listen to, which you could set to an unspecified address ( :: or 0.0.0.0 ) to listen to all interfaces.
  • Ensure that if you use a firewall, it does not block external access to your server. This depends on your setup and I would advice too check the manual of your firewall software on how to do that. On Linux you typically have ufw as a frontend for iptables or use the latter directly.
  • Ensure that your static IP is publically reachable (if you want to access your server from the public internet). A lot of ISPs do not offer customers a public IPv4 address, but instead use NAT to offer you access to the IPv4 internet. To verify this, you could use a site, such as ifconfig.co to see your public ip address and if this matches your static ip address it should work. If the IPs do not match, you might only have a static IP inside your home network, but not one that is publically routed to/from the internet. If the address shown by ifconfig.co matches the IP of your router, you can enable port forwarding in your router to the host running your server. This, however, strongly depends on how your network is set up.

If all of these apply, you should be able to access the server using your public ip and the specified port. But you might want to consider securing the connection by using HTTPS instead of plain HTTP. Depending on the specifics of your setup you should be able to find many guides online on how to accomplish this. Just a few pointers:

  • You need an TLS key and certificate for your host. The key you have to generate for yourself and the certificate can be either self-signed or issued by an CA, such as lets-encrypt.
  • Then you either have to modify your application to use HTTPs instead of HTTP or change your application to only listen to local connections and placing it behind a reverse proxy that does the SSL termination for you. For this nginx and apache are both valid options with various ressources on the Internet on how to set them up.

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