I have searched a lot of managing sub domains using Golang web server. I think I have found two main solutions:
Using nginx as proxy server
Basically nginx points to different servers on different ports evaluating the incoming domain name.
Using Golang server itself
Different handlers pointing to different sub handlers.
My question is if there is pros and cons with either approach?
Or is there other options?
Don’t forget Caddy as replacement for nginx.
Using real web server should allow easier handling of multiple domains specially if handler implementation (purpose) is completely different. This would also allow single responsibility and eventually better horizontal scaling.
Should I interpret this as avoid Golang web server?
No, you can safely use Go http server in production, but in that case you may need to apply some middlewares (https://github.com/go-chi/chi/tree/master/middleware) like rate limiter, compress, timeout, etc. If you handle all domains (subdomains) using the same code, you can do that way, but if your domains (subdomains) will have completely different apps/contents, it makes sense to do them completely independent (as services). Each of them would again use Go http server, but you can put either nginx or Caddy in the front to take care about routing, etc (again compress, rate limiting, tls encryption). In this second approach, you can scale each domain sevice independently.
If you need further help, please share what kind of content your domains would have, so just few examples.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.