我有一个简单的nginx,node.js设置,我想迁移到Vagrant,Docker世界。我不知道如何处理IP和端口。
我的目标是在浏览器中看到我的Hello World
,在端口80上看到最好的情况,只需拨打我的主机http://example.com
。
更新 我自己找到了解决方案 - 我在这里创建了一个简单的样板: https://github.com/ezmilhouse/docker 随意从这里继续。
app.js
var app = express();
app.route('*').all(function(req, res) {
res.send('Hello World!');
});
app.listen(2000)
nginx.conf
upstream example.com {
# using the vagrant private network IP (I guess?)
# using the node port
server 192.168.33.10:2000
}
server {
# ports nginx server is listen to
listen 80;
listen 443;
location / {
# upstream proxy
proxy_pass http://example.com;
# ...
}
}
Vagrantfile.proxy
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision "docker"
# settimg a hostname that matches nginx upstream (I guess?)
config.vm.hostname = "example.com"
# setting a private network IP, node.js and nginx run on this IP (i guess?)
config.vm.network "private_network", ip: "192.168.33.10"
end
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.define "nginx" do |app|
# forward the nginx port (I guess?)
app.vm.network "forwarded_port", guest: 80, host: 80
app.vm.provider "docker" do |d|
d.build_dir = "./docker/nginx"
d.vagrant_vagrantfile = "./Vagrantfile.proxy"
end
end
config.vm.define "node" do |app|
# forward the node port (I guess?)
app.vm.network "forwarded_port", guest: 2000, host: 2000
app.vm.provider "docker" do |d|
d.build_dir = "./docker/node"
d.vagrant_vagrantfile = "./Vagrantfile.proxy"
end
end
end
/ nginx的/ Dockerfile
# ...
EXPOSE ["80"]
/节点/ Dockerfile
# ...
EXPOSE ["2000"]
Mac OS X / etc / hosts
192.168.33.10 example.com
我希望在浏览器中调用http://192.168.33.10
以通过nginx和Hello World
查看我的http://192.168.33.10:2000
以查看节点实例。因此,主机example.com
也不起作用。
我做错了什么?