英文:
How to run multiple Golang apps on a dedicated server?
问题
我是一个Go的新手,我在尝试弄清楚如何在专用服务器上部署我的应用程序。
当我使用PHP时,我使用的是标准设置:
但是我对如何部署我的Go应用程序感到困惑。
我知道我可以在端口:80
上运行单个应用程序,但是如何运行多个应用程序呢?
这是一般的想法吗:
还是应该使用这样的方式:
有人可以澄清大多数Go开发者部署他们的应用程序的方式吗?谢谢!
英文:
I'm a Go newbie and I'm stuck trying to figure out how to deploy my apps on a dedicated server.
When I worked with PHP I used the standard setup:
But I'm confused as to how I'm supposed to deploy my Go apps.
I know I can run a single app on port :80
but how do I run multiple apps?
Is this the general idea:
Or should I be using something like this:
Can someone clarify the way most Go developers deploy their apps?
Thanks!
答案1
得分: 3
如果您需要多个应用程序来处理HTTP请求,您应该考虑使用Nginx作为反向代理。您可以将所有在给定路由(例如/api)上的请求转发到一个服务,将所有在另一个路由(例如/ui)上的请求转发到第二个服务,只要它们绑定到不同的端口即可。
英文:
If you need multiple apps to serve HTTP requests, you should definitely consider using Nginx as a reverse proxy. You can forward all requests on a given route, say /api to one service and /ui to a second service, provided they are bound to different ports.
答案2
得分: 3
我强烈推荐使用Caddy。您可以在不同的端口上设置服务器上的所有应用程序(尤其是较高的端口,例如1024及以上,这样它们就不需要root权限),然后使用proxy
指令将流量转发到您的应用程序等。作为额外的好处,您还可以免费获得Let's Encrypt证书支持!
有关proxy
指令的更多信息,请访问https://caddyserver.com/docs/proxy。
英文:
I'd highly recommend going with Caddy. You can set up you server with all the apps on different ports (esp. higher ports i.e. 1024 and up, so they don't need to be root), and then use proxy
directives to forward traffic to your apps and such. As a bonus, you also then get free Let's Encrypt certificate support!
https://caddyserver.com/docs/proxy for more on the proxy
directive
答案3
得分: 1
你可能想要了解一下Traefik(https://traefik.io/),这是一个基于Go语言的Web代理。
英文:
You might want to look a Traefik (https://traefik.io/), a go based web proxy
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论