dsymx68408 2016-01-03 19:48
浏览 45
已采纳

将Go Web服务器部署到Google计算引擎

I just started to test Google compute engine. Now I'm trying to deploy my Go (golang) application on it, so that it can be reached from outside. I use compute engine in favor of the app engine, since my application requires a MongoDB database.

I did the following:

  1. create compute engine instance
  2. setup up firewall so that port 1234 is open and IP is static
  3. install MongoDB
  4. upload my application
  5. start

The application starts just fine. But I cannot reach it from outside if I open it in my browser with ip:1234. I also tried to start it on port 80 as root user, but this didn't work neither.

The server is configured as following:

{
    "host": "localhost:1234",
    "dbhost": "localhost",
    "db": "dbname",
    "logfile": "log"
}

When I'm using an apache server it servers port 80 and the page is displayed... OS is ubuntu 14.04.

The main simply adds some handlers to a mux and adds a FileServer to the public dir:

mux.Handle("/", http.FileServer(http.Dir(public_dir)))
// [...]
if err := http.ListenAndServe(cfg.Host, mux); err != nil {
    panic(err)
}

So what's the issue here?

  • 写回答

1条回答 默认 最新

  • douzi9430 2016-01-03 19:57
    关注

    Try changing host from localhost to 0.0.0.0, because right now it's only listening to "inside" requests.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行