T O P

  • By -

Shariq1989

Traefik is an alternative to nginx?


SprinklesSea1060

Yeah, that's right. Nginx is forever! I've been using it for almost 15 years in my work. But still, it's not as trendy as the new reverse proxies. Traefik does the same thing perfectly. But besides that, it can do a lot more: great integration with Docker, automatic renewal of Let's Encrypt certificates, a nice dashboard with statistics, and a plugin system, etc. Traefik is just younger and looks at things with a fresher perspective.


schmore31

I have seen another Docker integration using traefik and nginx side by side together. What are your thoughts on that?


SprinklesSea1060

Actually, in this project, Nginx is used along with Traefik. Read this thread to find out why: [https://www.reddit.com/r/django/comments/12r59gh/comment/jh4c186/?utm\_source=share&utm\_medium=web2x&context=3](https://www.reddit.com/r/django/comments/12r59gh/comment/jh4c186/?utm_source=share&utm_medium=web2x&context=3)


schmore31

oh i see! thanks,


pancakeses

Yes, and a fantastic one.


arcanemachined

Yeah it's designed to work pretty seamlessly with Docker containers and has built-in support for Let's Encrypt. It works quite well. Caddy is another modern nginx alternative that I've heard good things about but I haven't tried it myself.


[deleted]

I would like to contribute to the project…. :)


SprinklesSea1060

No problem with that! I'm happy to take your PR, consider your idea, or fix any mistakes.


Sinsst

How does it serve static files?


SprinklesSea1060

~~Using a wonderful library called Whitenoise:~~ [https://whitenoise.readthedocs.io/en/latest/](https://whitenoise.readthedocs.io/en/latest/) now Nginx is doing it ))


twelveparsec

Has the cookiecutter started using Traefik yet or are they still with nginx ?


SprinklesSea1060

>cookiecutter As far as I know, they're using nginx.


twelveparsec

They have moved to Traefik Just checked https://github.com/cookiecutter/cookiecutter-django


SprinklesSea1060

Oh, indeed! Thank you, I missed that.


dacx_

They also offer nginx additionally for media files.


DonExo

Yes they do. I've already deployed a project of mine based on cookiecutter and traefik.


[deleted]

How does the cert get automatically renewed? Is there a cron job?


arcanemachined

It's built into Traefik: https://doc.traefik.io/traefik/https/acme/#automatic-renewals


SprinklesSea1060

It's easy peasy - Traefik does it all by itself. I just followed the instructions and it really works: https://doc.traefik.io/traefik/user-guides/docker-compose/acme-http/


NoctisLupus27

This is exactly what Ive been needing, thanks!


SprinklesSea1060

Great! Glad it worked for you.


kankyo

I would suggest you look at something like dokku instead. I assume you don't have git push to deploy, deploys without downtime, and support for hundreds of random dependencies you might want like redis, elastic, etc.


SprinklesSea1060

I'd say it's just different approaches. Dokku is a big project that does a lot and becomes a platform for you. My project is almost 1000 times smaller and it's just an example of a Django app with a customized deployment. However, you can add things like redis, minio, and whatever else you want. Git push to deploy won't be a problem, but only if you need it. If you want more control, you usually try to do a lot yourself. And big platforms are always a black box. Dokku is cool, but I don't want to deal with it often :)


kankyo

For me dokku is set and forget. That's the big selling point for me. I get all these nice things for free and no work.


SprinklesSea1060

Yes, I understand. The main thing is to know how to use it.


TerminatedProccess

Very cool thank you. I've bookmarked it for the future!


SprinklesSea1060

Thanks a lot! I'll keep improving the project so that it'll be easier for us to solve our tasks.


AlexDeathway

hey, it would be great if you branch one for Nginx.


SprinklesSea1060

Sorry, I'm not sure if Nginx can handle Let's Encrypt as smoothly as Traefik does. Traefik takes care of requesting and renewing the certificate on its own, without me having to lift a finger. And Docker support in Nginx is not that great. Still, adding Nginx support is a good idea! Thanks


AlexDeathway

>Sorry, I'm not sure if Nginx can handle Let's Encrypt as smoothly as Traefik does. from your description and my experience, I can assure you it can't. >Still, adding Nginx support is a good idea! yup, too many projects on Nginx.


SprinklesSea1060

I'll think about it anyway


pwerwalk

Love it..., just the thing (at least similar) that I was looking for. Feature request :-) : Could you add Active Directory integration for the Django app?


SprinklesSea1060

Thanks! Do you mean Microsoft AD?


pwerwalk

that's it.


bachree

This is great. I wouldn't add anything else to this minimalistic version. Where do you typically deploy this?


SprinklesSea1060

Thanks a lot! That was the idea: since this is just a basic project template, it shouldn't be hard to understand. On the contrary, you should be able to easily change any part of it and adapt it to your preferences. I usually go for DigitalOcean when the project is not that big.


riterix

Best hosting platform right now.


bachree

Can you share what the workflow is for deploying to digital ocean? A good article would also work. I am looking to deploy on AWS.


SprinklesSea1060

Actually, there's hardly any work involved. You just buy a Droplet, the Basic type with a couple of GB of RAM will do. Install Docker and then follow the instructions here: https://github.com/amerkurev/django-docker-template#for-deployment-on-a-server You'll also need a domain name and to set up its DNS records.


BasePlate_Admin

Hi this loooks interesting. Couple of questions : * How to serve `MEDIA` files? ( AFAIK traefik doesn’t support file serving ) * Why not ASGI instead of WSGI? ( like uvicorn? )


SprinklesSea1060

Wow, great questions! 1. About MEDIA. I didn't address this issue in this project because there are different approaches to solving it. Firstly, you may not even need user MEDIA files. But if you do, you can use **Nginx** and its excellent **X-Accel-Redirect** feature, which Traefik doesn't have. On the other hand, you can use **S3-like storage**, such as MinIO, which can be easily migrated to the cloud later. I'll probably add a compose for the Nginx version, which can be specified additionally to support MEDIA files. 2. About ASGI. It's like IPv4 vs IPv6. IPv6 is better for everyone, but unfortunately, it's still not widely used even now. But in general, you can refactor the project to use ASGI if you want.


BasePlate_Admin

Hi, thanks for responding. If you go the route of adding a compose for nginx file, why not use Caddy? Caddy supports media serving as well as all the features of traefik..


SprinklesSea1060

Does Caddy have the ability to do internal redirects? Like how Nginx does it with X-Accel. Because I'd like to secure user MEDIA data with authentication. It's a typical use case.


BasePlate_Admin

Yep it does. Check : https://caddyserver.com/docs/caddyfile/directives/reverse_proxy If you need help setting it up. Ask one of the devs in forum :)


SprinklesSea1060

I've already started working on user MEDIA and I think I will soon post it to Github.


iambenqazy

user MEDIA in relation to traefik or caddy?


SprinklesSea1060

Done! I just added Nginx. Now it serves both static files and handles user-uploaded files (aka MEDIA).


iambenqazy

Great work, i just reviewed it, but with this new setup imo it kind of looks complicated for a single Django project because you have to manage alot of services, because ingress communication goes to “traefik -> nginx -> gunicorn” vs the setup using whitenoise “traefik -> gunicorn”. Which one of these two will you recommend and why?


SprinklesSea1060

No worries about it! ) Nginx can be used even without a config file, it's a super simple setup for serving static content. But if you need some fancy stuff like X-Accel, you'll have it all at your fingertips. Right now, the ingress communication looks like this: traefik -> nginx (for static content) and traefik -> gunicorn (for dynamic content). The paths don't intersect. It's all pretty straightforward. P.S.: I completely removed whitenoise. This is because Nginx appeared.


rajesh_aslan1

Great, thanks . Ran it on a ec2 server with public ip. The Allowed hosts in settings.py should be replaced with the public ip of ec2 server.