donglei2022
2016-10-06 10:57
浏览 87
已采纳

在一个IP上托管多个Golang站点并根据域请求提供服务?

I'm running a VPS with Ubuntu installed. How can I use the same VPS (same IP) to serve multiple Golang websites without specifying the port (xxx.xxx.xxx.xxx:8084) in the url?

For example, Golang app 1 is listening on port 8084 and Golang app 2 is listening on port 8060. I want Golang app 1 to be served when someone requests from domain example1.com and Golang app 2 to be served when someone requests from domain example2.com.

I'm sure you can do this with Nginx but I haven't been able to figure out how.

图片转代码服务由CSDN问答提供 功能建议

我正在安装Ubuntu的情况下运行VPS。

如何在不指定网址的端口(xxx.xxx.xxx.xxx:8084)的情况下使用相同的VPS(相同的IP)来服务多个Golang网站?

例如,< strong> Golang应用程序1正在监听端口8084 ,而 Golang应用程序2正在监听端口8060 。 我希望有人从域 example1.com 请求提供Golang应用程序1,有人从域 example2.com 请求提供Golang应用程序2。

我确定您可以使用Nginx进行此操作,但我无法弄清楚该怎么做。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dounue1965 2016-10-06 11:17
    已采纳

    Please, try out the following code,

    server {
       ...
       server_name www.example1.com example1.com;
       ...
       location / {
          proxy_pass app_ip:8084;
       }
       ...
    }
    
    ...
    
    server {
       ...
       server_name www.example2.com example2.com;
       ...
       location / {
          proxy_pass app_ip:8060;
       }
       ...
    }
    

    app_ip is the ip of the machine wherever same is hosted, if on the same machine, put http://127.0.0.1 or http://localhost

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题