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?

  • 写回答

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;
            ...
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀