我在一个 vps 中分别在两个 docker 容器中运行两个网站。 例如www.myblog.com 和 www.mybusiness.com
如何在vps中实现virtualhost,让两个网站都可以使用80端口。
我在其他地方问过这个问题,并被建议看一下:https://github.com/hipache/hipache和 https://www.tutum.co/ 它们看起来有点弯曲。我正在尝试寻找是否有一种直接的方法来实现这一目标。谢谢!
另外,忘了说我的vps是一个Ubuntu 14.04的盒子。
最佳答案
看看jwilder/nginx-proxy项目。
Automated nginx proxy for Docker containers using docker-gen
这是代理 docker 容器的最简单方法。每次重新启动容器或启动新容器时,您都不需要编辑代理配置文件。 docker-gen 为您自动完成这一切它为 nginx 生成反向代理配置,并在容器启动和停止时重新加载 nginx。
Usage
To run it:
$ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock \ jwilder/nginx-proxy
Then start any containers you want proxied with an env var VIRTUAL_HOST=subdomain.youdomain.com
$ docker run -e VIRTUAL_HOST=foo.bar.com ...
Provided your DNS is setup to forward foo.bar.com to the a host running nginx-proxy, the request will be routed to a container with the VIRTUAL_HOST env var set.
Multiple Ports
If your container exposes multiple ports, nginx-proxy will default to the service running on port 80. If you need to specify a different port, you can set a VIRTUAL_PORT env var to select a different one. If your container only exposes one port and it has a VIRTUAL_HOST env var set, that port will be selected.
关于web - 我的网站在 docker 容器中运行,如何实现虚拟主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29519215/