traefik适合做docker容器的反向代理,负载均衡,但它做web静态页面server却不是那么容易,nginx来得更容易些,可能是我个人使用不当,没深究了。
所以就想着用nginx做web静态页面server,问题是nginx,traefik都想使用它们自己默认的80端口,而且在同一台机器上,怎么办呢?
一开始,我想的思路如下图所示:
nginx转发给traefik.png
但试了几回,都没成功!很不爽。于是转换思路,能不能由traefik转发给nginx呢?如下图:
traefik转发给nginx.png
哈哈,这样居然成功了!
多个静态页面的配置如下,(docker-compose跑的openresty)
version: '3'
services:
openresty:
image: openresty/openresty
container_name: openresty
#network_mode: bridge
restart: always
tty: true
#ports:
#- 80:80
ulimits:
nofile:
soft: 2048
hard: 2048
networks:
- web
labels:
- traefik.backend=web
- traefik.frontend.rule=Host:s.test.net,www.test.net
- traefik.port=80
environment:
- TZ=Asia/Shanghai
volumes:
- /data/openresty/conf:/usr/local/openresty/nginx/conf
- /data/openresty/logs:/usr/local/openresty/nginx/logs
- /data/openresty/html:/usr/local/openresty/nginx/html
- /data/wwwroot/test/ROOT/:/data/wwwroot/test/ROOT/
- /data/fileroot/dd/:/data/fileroot/dd/
- /data/wwwroot/ok/:/data/wwwroot/ok/
networks:
web:
external:
name: traefik_net
网友评论