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 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码