nginxa:
container_name: nginxa
image: registry.cn-shenzhen.aliyuncs.com/beni/nginx:latest
volumes:
- C:/data/nginxa/conf.d:/etc/nginx/conf.d
- C:/data/nginxa/www:/usr/share/nginx/html
nginxb:
container_name: nginxb
image: registry.cn-shenzhen.aliyuncs.com/beni/nginx:latest
volumes:
- C:/data/nginxb/conf.d:/etc/nginx/conf.d
- C:/data/nginxb/www:/usr/share/nginx/html
nginxc:
container_name: nginxc
image: registry.cn-shenzhen.aliyuncs.com/beni/nginx:latest
ports:
- 80:80
volumes:
- C:/data/nginxc/conf.d:/etc/nginx/conf.d
links:
- nginxa:nginxa
- nginxb:nginxb
server {
listen 80;
server_name a.pytask.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://nginxa:80/;
}
}
server {
listen 80;
server_name b.pytask.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://nginxb:80/;
}
}
a.pytask.com訪問應用ab.pytask.com訪問應用b
其中a和b兩個容器可以不做端口映射,因爲c是用過link方式訪問a和b
c做的是反向代理,開放80端口給外部訪問