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

huangapple go评论83阅读模式
英文:

Using Proxy server to switch between Golang Applications

问题

我有一个安装了CentOS的服务器,在那里我将运行至少4个Golang应用程序,每个应用程序都是一个不同的站点,我应该能够通过以下域名/子域名在浏览器中访问它们:

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

因此,我需要配置某种软件来将请求重定向到正确的Golang进程。每个站点将在不同的端口上运行,所以例如,如果有人调用dev00.mysite.com,我应该能够将该请求发送到dev00站点的进程(这是为了开发目的,而不是生产目的)。因此,我开始相信我需要Nginx或Caddy,正如我所读到的,但我对它们都没有经验。
有人可以确认这是解决这个问题的方法吗?我在哪里可以找到一些配置示例,演示这些服务器如何重定向到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?

答案1

得分: 2

是的,Nginx可以解决你的问题:

  1. 使用Go或Caddy的标准库启动一个Web服务器。
  2. 使用Nginx将请求重定向到Go应用程序:

以下是Nginx的示例配置:

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;
        ...
    }
}
英文:

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

huangapple
  • 本文由 发表于 2017年4月10日 23:53:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/43327793.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定