大网数据广告活动
服务器运维问答

Should I remove Nginx from all docker applications if I were adding a traefik reverse proxy?

· 52CE 我爱测

I wish to significant reduce number of public exposed ports, which currently used by many docker applications. Each docker application consists of at least a Nginx and a Python Flask, which is a pretty common setup technique - ht…

问题原文

原帖链接 · Cheok Yan Cheng · CC BY-SA 4.0

I wish to significant reduce number of public exposed ports, which currently used by many docker applications.

Each docker application consists of at least a Nginx and a Python Flask, which is a pretty common setup technique - https://blog.nolanemirot.com/2016/03/11/deploy-a-flask-app-with-gunicorn-and-docker/

I plan to follow this tutorial to setup https://www.digitalocean.com/community/tutorials/how-to-use-traefik-as-a-reverse-proxy-for-docker-containers-on-ubuntu-18-04

Unlike my docker applications which consists of Nginx and Python Flask, the given example is using WordPress as docker application example.

For my case, I was wondering, whether a Nginx still necessary, at each docker application side? Is it redundant, or should it still be there?

已采纳解答

原帖链接 · Ivan · CC BY-SA 4.0

[edit] Traefik will communicate with your docker daemon. It will listen for containers with "traefik" flags, and adjust its configuration. for example:

-l traefik.frontend.rule=Host:monitor.your_domain
-l traefik.port=8080

If your container is running an application that is listening on a network port on the docker network interface, then you just need to set -l traefik.port={you_apps_port}, and it should work. you need the container to be on the same docker network as traefik, which is "--network {name}" option is for.
So as long as your flask app can listen on a port, you won't need nginx. You also won't need to do port binding between your flask app container and your host.
You only need to access the traefik container on port 80 from outside docker networks.
If you want to have multiple apps running you might need to set up your hosts file or a (local?) DNS to point to your traefik host with multiple names, e.g:

127.0.0.1  app1.mytraefik
127.0.0.1  app2.mytraefik
127.0.0.1  app3.mytraefik

then set app1's label "frontend.rule=Host:app1.mytraefik". Traefik will read your http HOST header and direct requests over the docker network to your container on the port in the "traefik.port" label

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。