douli2876 2018-02-22 04:20
浏览 57
已采纳

访问Golang Web服务器

I know that Golang contain native built-in web server(net/http) that can be used as server without using external web servers(apache,nginx,etc). For local development, you simply run http.ListenAndServe and your server is ready locally.

My question is, How to set up your golang app to be accessed by others publicly without the need of external web servers?

  • 写回答

2条回答 默认 最新

  • dongyan4424 2018-02-28 08:13
    关注

    In your golang code, you don't need to do anything else except specifying the port your app listening to. After setting the port(e.g :8080), you need to do these things to make it accessible:

    • If you want your app to be accessible internally(LAN/WLAN), check your private IP address, then access it from any other devices within your internal network. For example your private ip is 10.50.50.10 then access it with your port specified in your app: 10.50.50.10:8080
    • If you want your app to be accessible publicly(WAN), check your public IP. First you need to make sure the port you're using for your app to listen. Set your firewall to let the port open for public access. Then You must forward the port in the router. Port forwarding is done to let any request to your public IP and specific port you set to be forwarded to your device's IP(private IP) and the port your app listening. Search for port forwarding for specific OS and router you used for further information.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试