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

在一个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.

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制