I'm running a VPS with Ubuntu installed. How can I use the same VPS (same IP) to serve multiple Golang websites without specifying the port (xxx.xxx.xxx.xxx:8084) in the url?
For example, Golang app 1 is listening on port 8084 and Golang app 2 is listening on port 8060. I want Golang app 1 to be served when someone requests from domain example1.com
and Golang app 2 to be served when someone requests from domain example2.com
.
I'm sure you can do this with Nginx but I haven't been able to figure out how.
Please, try out the following code,
app_ip is the ip of the machine wherever same is hosted, if on the same machine, put
http://127.0.0.1
orhttp://localhost
Nginx free solution.
First of all you can redirect connections on port 80 as a normal user
Then use gorilla/mux or similar to create a route for every host and even get a "subrouter" from it
So the complete solution would be