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

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...

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

我想使用Golang处理多个域。

像这样,如果浏览器发送对 http://sampledomain.me 句柄的请求 配合特定的Golang程序

在其他情况下,我希望在一台服务器上有很多程序,并告诉每个程序处理每个域。

所有程序都在80上侦听,并且许多域都指向一台服务器。

有人可以帮助我吗?

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

相关推荐 更多相似问题