dongzaobei0942 2016-10-10 06:54
浏览 49
已采纳

Golang是否可以处理多个域?

I want to handle multi-domains with Golang.

Like this , If browser sends request for http://sampledomain.me handles it with specific Golang program ,

In other cases , I want many programs on one server and tell each one of them , to handle each domain.

All programs are listening on 80 and many domains point to one server.

Can anybody help me ?

Thx...

  • 写回答

4条回答 默认 最新

  • dongya6395 2016-10-10 08:26
    关注

    Your Go programs can't all listen on port 80. You'd need something in front, like nginx, to act as a reverse proxy. The following nginx config excerpt would forward two domains on to two different programs, each listening on different ports:

    server {
            listen 80;
            server_name www.domain1.com;
    
            location / {
                    proxy_pass http://127.0.0.1:8080;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host            $host;
                    proxy_read_timeout 600s;
            }
    
    }  
    
    server {
            listen 80;
            server_name www.domain2.com;
    
            location / {
                    proxy_pass http://127.0.0.1:8081;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host            $host;
                    proxy_read_timeout 600s;
            }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行