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节点负责整个集群管理工作,为集群提供管理接口,并 ...
随机推荐
- 史陶比尔Stabli机器人维修小细节
在工业自动化领域,史陶比尔机器人以其卓越的性能和可靠性而著称.然而,即使是尖端的设备,也难免会遇到Stabli机械手故障和问题.对于机器人维护和修理,每一个小细节都显得至关重要. 一.观察 首先,我们 ...
- Powershell 调用cmd 运行exe、bat、jar文件
1. 配置路径 $nginxPath = "C:\path\to\nginx" $redisPath = "C:\path\to\redis" $ruoyiAd ...
- c++常量引用,通过被引用变量修改数据无法同步到引用
正常情况下被引用的对象改变,常量引用的值也跟着改变.i和j是同一个对象,所以是同步的: int i = 42; const int& j = i; i = 43; cout << ...
- P5356 [Ynoi Easy Round 2017] 由乃打扑克
分块典题 左转数列分块入门2 一样的想法 排序+二分 但是发现我们只能求排名 于是二分答案然后分块+二分即可
- 浅谈Tox之一
本文分享自天翼云开发者社区<浅谈Tox之一>,作者:Moonriver What is tox? tox是通用的virtualenv管理和测试命令行工具,可用于: 使用不同的Python版 ...
- linux系统批量查找网站源码并替换字符,查找替换指定内容
问题描述:维护中需要批量修改代码中某个字符,如果单个打开页面进行修改则效率过低,linux系统下借助grep命令快速查找替换 命令示例1: grep -rl '查找的内容' . | xargs sed ...
- 【Matlab】求解复合材料层合板刚度矩阵及柔度矩阵
1. matlab文件结构 2. main.m代码 clc clear; warning off; %% %铺层角度数组 angles=[0 90 0]; % ° %单层厚度 ply_thicknes ...
- k8s Error: failed to prepare subPath for volumeMount "custom-logo" of container "grafana"
前言 使用 k8s 挂载卷文件时,使用了 hostPath,type: File volumeMounts: - mountPath: /usr/share/grafana/public/img/gr ...
- BUUCTF---BabyRSA(简单求解n)
题目 p+q : 0x1232fecb92adead91613e7d9ae5e36fe6bb765317d6ed38ad890b4073539a6231a6620584cea5730b5af83a3e ...
- 元模型:开启AI哲学思考的数字奇点
为推广动态模型让AI写的.动态模型和AI非常契合,元模型对AI有意义,所以让AI写更好.元模型其实是非常简单的一个模型,使用XML表示代码如下. <thing name="thing& ...