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.

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

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退