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
Swag^1 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
Caddy^2 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
:
Then run Caddy with docker as following docker-compose file:
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
Traefik^3 is also a reverse proxy server written in Go. I can run it as following docker-compose file:
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
感谢您的阅读,如果您觉得本文有用,快点击下方点赞按钮👍,让更多的人看到本文。
欢迎关注作者的微信公众号“newbe 技术专栏”,获取更多技术内容。
本文作者: newbe36524
本文链接: https://www.newbe.pro/Others/0x02A-Nginx-no-traefik-yes/
版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
版权声明: 本文为 InfoQ 作者【newbe36524】的原创文章。
原文链接:【http://xie.infoq.cn/article/9e8164422187793a0097ba19d】。
本文遵守【CC BY-NC-SA】协议,转载请保留原文出处及本版权声明。
评论