在一个IP上托管多个Golang站点并根据域请求提供服务? [英] Host Multiple Golang Sites on One IP and Serve Depending on Domain Request?
问题描述
我正在运行安装了Ubuntu的VPS。如何在不指定端口(xxx.xxx.xxx.xxx:8084)的情况下使用相同的VPS(相同IP)为多个Golang网站提供服务?
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?
例如, Golang应用1正在侦听端口8084 , Golang应用2正在侦听端口8060 。当有人从域 c> example1.com
请求时,我希望Golang应用1得到投放,而当有人从域 example2.com请求时,Golang应用2将被投放。
。
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
.
我相信你可以用Nginx做到这一点,但我一直无法弄清楚。
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,
server {
...
server_name www.example1.com example1.com;
...
location / {
proxy_pass app_ip:8084;
}
...
}
...
server {
...
server_name www.example2.com example2.com;
...
location / {
proxy_pass app_ip:8060;
}
...
}
app_ip是ip如果在同一台机器上,请将 http://127.0.0.1
或 http:// localhost
app_ip is the ip of the machine wherever same is hosted, if on the same machine, put http://127.0.0.1
or http://localhost
这篇关于在一个IP上托管多个Golang站点并根据域请求提供服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!