将不同的域指向单个EC2实例上的不同Docker容器?

问题描述:

我有一个运行在Docker容器中的简单NodeJS站点,其端口映射到主机上的端口80。我有一个指向EC2实例IP的域,并且一切正常。

I have a simple NodeJS site running inside a Docker container, with its ports mapped to port 80 on the host. I have a domain pointing to the IP of the EC2 instance, and everything is working as expected.

如果我想运行另一个从Docker容器上分离的NodeJS站点,在同一实例中,如何将特定域名映射到特定Docker容器?

If I want to run another, separate NodeJS site from a Docker container on the same instance, how can I map specific domain names to specific Docker containers?

例如,假设我的EC2实例的IP为22.33.44.55,并且我的域为domain -a.com和domain-b.com。我的dockerized NodeJS应用程序是siteA和siteB。

Eg, let's assume the IP of my EC2 instance is 22.33.44.55 and my domains are domain-a.com and domain-b.com. My dockerized NodeJS applications are siteA and siteB.

domain-a.com配置为指向22.33.44.55。 siteA正在侦听该IP地址到端口80,这是我当前拥有的地址。

domain-a.com is configured to point to 22.33.44.55. siteA is listening on that IP address to port 80 - this is what I currently have.

domain-b.com配置为指向22.33.44.55。我希望将此流量映射到siteB Docker容器。

domain-b.com is configured to point to 22.33.44.55. I want this traffic mapped to the siteB Docker container.

您可以在主机上设置Nginx反向代理并绑定为单独的代理端口。这篇文章中的问题和答案很好地解释了这一点,因此我不再赘述。

You could setup a nginx reverse proxy on the host and bind to seperate ports. The question/and answer on this article explain it quite nicely so I won't repeat it all:

https://www.digitalocean.com/community/questions / how-to-bind-multiple-domains-ports-80-and-443-docker-contained-applications