我的网站运行在docker容器中,如何实现虚拟主机? [英] My websites running in docker containers, how to implement virtual host?
问题描述
例如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 项目。
使用docker-gen的Docker容器的自动化nginx代理
这是代码你的码头容器的最简单的方法。每次重新启动容器或启动新的容器时,都不需要编辑代理配置文件。这一切都会通过 docker-gen 自动为您生成,它为nginx生成反向代理配置,并重新加载nginx
用法
要运行它: / p>
$ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock \
jwilder / nginx-proxy
然后启动任何要使用env代理的容器var VIRTUAL_HOST = subdomain.youdomain.com
$ docker run -e VIRTUAL_HOST = foo.bar.com ...
如果您的DNS设置为将foo.bar.com转发到运行nginx-proxy的主机,则请求将将路由到具有VIRTUAL_HOST env var set的容器。
多个端口
如果容器暴露了多个端口,nginx-proxy将默认服务运行端口80.如果需要指定一个不同的端口,可以设置一个VIRTUAL_PORT env var来选择一个不同的端口。如果您的容器仅暴露一个端口,并且具有VIRTUAL_HOST env var set,则将选择该端口。
I am running two websites in two docker containers respectively in a vps. e.g. www.myblog.com and www.mybusiness.com
How can I implement virtualhost in the vps so that the two websites can both use port 80.
I asked this question somewhere else, and was suggested to take a look at: https://github.com/hipache/hipache and https://www.tutum.co/ They look a bit curving. I am trying to find if there is a straightforward way to achieve that. Thanks!
In addition, forgot to mention my vps is a Ubuntu 14.04 box.
Take a look at jwilder/nginx-proxy project.
Automated nginx proxy for Docker containers using docker-gen
It's the easiest way to proxy your docker containers. You don't need to edit the proxy config file every time you restart a container or start a new one. It all happens automatically for you by docker-gen which generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped.
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.
这篇关于我的网站运行在docker容器中,如何实现虚拟主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!