duangang2825
2017-04-10 15:53
浏览 53
已采纳

使用代理服务器在Golang应用程序之间切换

I have a server with CentOS, and there I will have at least 4 Golang applications running, every one of them is a different site that I should be able to access in the browser with domain/subdomains as follows:

  • dev00.mysite.com
  • dev01.mysite.com
  • dev02.mysite.com
  • dev03.mysite.com

So, I need to configure some kind of software that redirects the requests to the correct Golang process. Every site will be running in a different port, so for example if someone calls dev00.mysite.com I should be able to send that request to the process of dev00 site (this is for development porpouses, not production). So, here I'm starting to believe that I need Nginx or Caddy as I read, but I have no experience with none of them. Can someone confirm that this is the way to fix that problem? and where can I find some example of configuration of any of that servers redirecting to Golang applications?

And, in the future if a have a lot (really a lot) of domains running in the same server, which of that servers is better? who is better with high load?

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

我有一台装有CentOS的服务器,在那里我将至少运行4个Golang应用程序,每个应用程序都是 我应该能够在具有域/子域的浏览器中访问的其他站点,如下所示:

  • dev00.mysite.com
  • dev01.mysite.com
  • dev02.mysite.com
  • dev03.mysite.com

    因此,我需要配置某种将请求重定向到正确的Golang流程的软件。 每个站点都将在不同的端口上运行,因此,例如,如果有人呼叫dev00.mysite.com,我应该能够将该请求发送到 dev00 站点的进程(这是针对开发用途,不是 生产)。 因此,在这里,我开始相信我在阅读时需要Nginx或Caddy,但是我对它们都不了解。 有人可以确认这是解决此问题的方法吗? 哪里可以找到重定向到Golang应用程序的任何服务器的配置示例?

    而且,将来,如果有很多(确实很多)域在运行, 同一台服务器,哪个服务器更好? 谁在高负载下更好?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpp34603 2017-04-10 16:32
    已采纳

    Yes, Nginx can solve your problem:

    1. Start a web server using the standard library of Go or Caddy.
    2. Redirect request to Go application using Nginx:

    Example Nginx configuration:

    server {
        listen 80;
        server_name dev00.mysite.com;
        ...
    
        location / {
            proxy_pass http://localhost:8000;
            ...
        }
    }
    
    server {
        listen 80;
        server_name dev01.mysite.com;
        ...
    
        location / {
            proxy_pass http://localhost:8001;
            ...
        }
    }
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题