Nginx No, Traefik Yes
As we all know, Nginx is a very popular reverse proxy server. It is very stable and has a lot of features. But I choose Traefik instead of Nginx as a reverse proxy in test environment since it is more suitable for my use case. In this post, I will explain why I choose Traefik instead of Nginx.
Background
I have a test environment which is running on a single server. It has a lot of services running on it. I want to expose these services to the internet. So I need a reverse proxy server to do this. I am used to using Swag as a reverse proxy for years, witch is based on Nginx. But it is a little bit hard to configure. So I want to find a better solution.
I want to find a reverse proxy server which meets the following requirements:
- It should be containerized. I don't want to install it on the host machine.
- It should be easy to configure.
- It should support Let's Encrypt to generate SSL certificates automatically.
- It should be easy to migrate to production environment if needed.
Swag
Swag1 is a reverse proxy server based on Nginx, witch I used for years. It meets all the requirements above. Swag project provides a docker image to run it. And dozens of Nginx configuration template files for developers to use. If you are familiar with Nginx, you can easily configure it. But it is way too complex for beginners.
I choose Swag as my reverse proxy server instead of bare Nginx, because it supports Let's Encrypt to generate SSL automatically by adding a few lines of configuration. It is very convenient.
Caddy
Caddy2 is a web server written in Go. I tried this solution to solve my problem after doing some research.
For example, if you want to expose a service running on port 80, you just need to create a file named Caddyfile:
api.newbe.pro {
reverse_proxy api:80
}
ws.newbe.pro {
reverse_proxy ws:80
}
Then run Caddy with docker as following docker-compose file:
version: "3.4"
services:
caddy:
image: caddy
container_name: caddy
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- ./data/caddy:/data
- ./data/caddy/config:/config
api:
image: newbe36524/newbe.api
container_name: api
restart: unless-stopped
environment:
- ASPNETCORE_ENVIRONMENT=Development
volumes:
- ./data/api:/app/data
ws:
image: newbe36524/newbe.ws
container_name: ws
restart: unless-stopped
environment:
- ASPNETCORE_ENVIRONMENT=Development
volumes:
- ./data/ws:/app/data
Then configure my DNS to point api.newbe.pro and ws.newbe.pro to my server with A record. Then I can access my api service and ws service with https://api.newbe.pro and https://ws.newbe.pro respectively.
I finally gave up this solution because Caddy does not support many build-in plugins as Traefik does. Of course, you can compile Caddy with plugins you need. But I don't want to do this.
Traefik
Traefik3 is also a reverse proxy server written in Go. I can run it as following docker-compose file:
version: '3.4'
secrets:
azure_client_id:
file: "./secrets/azure_client_id.secret"
azure_client_secret:
file: "./secrets/azure_client_secret.secret"
azure_tenant_id:
file: "./secrets/azure_tenant_id.secret"
azure_subscription_id:
file: "./secrets/azure_subscription_id.secret"
azure_resource_group:
file: "./secrets/azure_resource_group.secret"
services:
reverse-proxy:
# The official v2 Traefik docker image
image: traefik:v2.10
container_name: "traefik"
# Enables the web UI and tells Traefik to listen to docker
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myresolver.acme.dnschallenge=true"
- "--certificatesresolvers.myresolver.acme.dnschallenge.provider=azuredns"
- "--certificatesresolvers.myresolver.acme.email=contact@newbe.pro"
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
environment:
- "AZURE_CLIENT_ID_FILE=/run/secrets/azure_client_id"
- "AZURE_CLIENT_SECRET_FILE=/run/secrets/azure_client_secret"
- "AZURE_TENANT_ID=/run/secrets/azure_tenant_id"
- "AZURE_SUBSCRIPTION_ID=/run/secrets/azure_subscription_id"
- "AZURE_RESOURCE_GROUP=/run/secrets/azure_resource_group"
secrets:
- "azure_client_id"
- "azure_client_secret"
- "azure_tenant_id"
- "azure_subscription_id"
- "azure_resource_group"
ports:
# The HTTP port
- "80:80"
- "443:443"
- "443:443/udp"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
# So that Traefik can listen to the Docker events
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./letsencrypt:/letsencrypt"
api:
image: newbe36524/newbe.api
container_name: api
restart: unless-stopped
environment:
- ASPNETCORE_ENVIRONMENT=Development
labels:
- "traefik.enable=true"
- "traefik.http.routers.api.rule=Host(`api.newbe.pro`)"
- "traefik.http.routers.api.entrypoints=websecure"
- "traefik.http.routers.api.tls.certresolver=myresolver"
ws:
image: newbe36524/newbe.ws
container_name: ws
restart: unless-stopped
environment:
- ASPNETCORE_ENVIRONMENT=Development
labels:
- "traefik.enable=true"
- "traefik.http.routers.ws.rule=Host(`ws.newbe.pro`)"
- "traefik.http.routers.ws.entrypoints=websecure"
- "traefik.http.routers.ws.tls.certresolver=myresolver"
You can notice that all the configuration is in docker-compose file. I don't need to create any other configuration file, it is very convenient. Traefik is not only support docker as a provider to automatically discover services, but also support Kubernetes if I want to migrate to Kubernetes in the future.
Conclusion
I choose Traefik instead of Nginx as a reverse proxy in test environment because it is more suitable for my use case. It is cloud native and easy to configure. I don't need to create any other configuration file. I can configure everything in docker-compose file.
References
感谢阅读,如果觉得本文有用,不妨点击推荐或者在评论区留下 Mark,让更多的人可以看到。
欢迎关注作者的微信公众号“newbe技术专栏”,获取更多技术内容。
- 本文作者: newbe36524
- 本文链接: https://www.newbe.pro/Others/0x02A-Nginx-no-traefik-yes/
- 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
https://github.com/linuxserver/docker-swag
https://caddyserver.com/v2
https://doc.traefik.io/traefik/
https://learn.microsoft.com/azure/dns/dns-zones-records?WT.mc_id=DT-MVP-5004283
Nginx No, Traefik Yes的更多相关文章
- 在单机Docker上安装 Traefik 反向代理-负载均衡器
一.创建Traefik和容器应用的连接网络 sudo docker network create traefik-net 二.下载Traefik样本配置文件wget https://raw.githu ...
- Docker Swarm集群中部署Traefik负载均衡器
一.创建单节点的Docker Swarm集群 docker swarm init 二.在Swarm集群中创建一个网络 docker network create --driver=overlay tr ...
- Traefik 2.0 tcp 路由试用
对于tcp 的路由是基于sni (需要tls)但是可以通过统配(*) 解决不试用tls的,当然也可以让Traefik 自动生成tls 证书 以下是测试http 以及mysql 的tcp 路由配置(de ...
- 实操教程丨如何在K8S集群中部署Traefik Ingress Controller
注:本文使用的Traefik为1.x的版本 在生产环境中,我们常常需要控制来自互联网的外部进入集群中,而这恰巧是Ingress的职责. Ingress的主要目的是将HTTP和HTTPS从集群外部暴露给 ...
- Kubernetes 在生产环境中常用架构
Kubernetes 在生产环境中常用架构 首先,我们来梳理下Kubernetes生产架构,其设计适用于绝大多数环境.如下图所示 在该架构中,我们可以将其分为四层,如下: Client层:即Kuber ...
- 浅谈Kubernetes生产架构
注意本文,只是笔者针对Kubernetes生产环境运行的一些关于架构设计和实现方案的总结,内容很粗糙,同时也会不断完善. 首先,我们来梳理下Kubernetes生产架构,其设计适用于绝大多数环境.如下 ...
- Ingress介绍与安装配置
在 Kubernetes 集群中,Ingress是授权入站连接到达集群服务的规则集合,为您提供七层负载均衡能力.您可以给 Ingress 配置提供外部可访问的 URL.负载均衡.SSL.基于名称的虚拟 ...
- Kubernetes简述
一.Kubernetes特性 1.自动装箱 建构于容器之上,基于资源依赖及其他约束自动完成容器部署且不影响其可用性,并通过调度机制混合关键型应用和非关键型应用的工作负载于一点以提高资源利用率. 2.自 ...
- React 服务端渲染最佳解决方案
最近在开发一个服务端渲染工具,通过一篇小文大致介绍下服务端渲染,和服务端渲染的方式方法.在此文后面有两中服务端渲染方式的构思,根据你对服务端渲染的利弊权衡,你会选择哪一种服务端渲染方式呢? 什么是服务 ...
- k8s集群介绍
Kubernetes集群组件 一个典型的Kubernetes集群由多个工作节点和一个集群控制节点,以及一个集群状态存储系统etcd组成.其中Master节点负责整个集群管理工作,为集群提供管理接口,并 ...
随机推荐
- Linux命令行连接蓝牙设备
Linux命令行连接蓝牙设备 查看Bluetooth设备: hciconfig 启动一个Bluetooth设备,例如:hci0: hciconfig hci0 up 相关指令 查看特定的Bluetoo ...
- SMOTE算法解决样本不平衡
首先,看下Smote算法之前,我们先看下当正负样本不均衡的时候,我们通常用的方法: 抽样 常规的包含过抽样.欠抽样.组合抽样 过抽样:将样本较少的一类sample补齐 欠抽样:将样本较多的一类samp ...
- QT5笔记: 15. 其他显示组件的常用功能
其他显示组件的常用功能 代码 #include "widget.h" #include "ui_widget.h" Widget::Widget(QWidget ...
- Typora - typora主题样式
主题名称:github_harley.css(随便命名) 效果:Mac风格的代码块.更舒适的引用块风格. css harley01 /* 代码块主题 */ /* 顶部 */ .md-fences { ...
- burpsuite激活
激活burpsuite--教程 点击Start 文件,把三个框都选上 点击RUN,会自动启动,复制一下那个证书 粘贴刚刚复制的密钥,点击下一个即可 这里点击手动激活,复制请求,粘贴到刚刚那个激活程序的 ...
- word 批量制作ppt
将 Word 文档作为大纲,构建演示文稿 在 Word 文档中,单击"开始". 使用"样式"设置 Word 文档中内容的格式. 突出显示要用作幻灯片标题的内容, ...
- mysql的自增id
为图方便,建表直接用了mysql的自增id 开发时进行插入操作时,发现插入失败id也自增了,导致id不连续 并且无论是删除还是插入,id是一直在增加 查询结果 MySQL自增ID机制: InnoDB存 ...
- k8s v1.19版本之后,自签证书过期x509: certificate has expired or is not yet valid
前言 在 Kubernetes 1.16 版本之前,kubeadm 工具的 alpha certs 子命令用于生成和管理 Kubernetes 集群的证书.然而,从 Kubernetes 1.19 版 ...
- ubuntu install 下载安装包报错 subprocess installed post-installation script returned error exit status 10
前言 在 ubuntu 环境下使用 sudo apt-get install 安装软件包时,会报错 XXX 为安装软件包 dpkg:error processing package XXX (--co ...
- 解决排查 mongodb cpu使用率过高
前言 通过 top 命令,可以看到 MongoDB 的 CPU 使用率过高,CPU 过高会导致数据读写.处理异常缓慢,还会出现被系统抹杀进程的风险,这个问题 99.9999% 的可能性是用户使用上不合 ...
