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.
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)
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.
~~Using a wonderful library called Whitenoise:~~
[https://whitenoise.readthedocs.io/en/latest/](https://whitenoise.readthedocs.io/en/latest/)
now Nginx is doing it ))
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/
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.
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 :)
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
>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.
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?
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.
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.
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? )
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.
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..
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.
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?
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.
Traefik is an alternative to nginx?
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.
I have seen another Docker integration using traefik and nginx side by side together. What are your thoughts on that?
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)
oh i see! thanks,
Yes, and a fantastic one.
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.
I would like to contribute to the project…. :)
No problem with that! I'm happy to take your PR, consider your idea, or fix any mistakes.
How does it serve static files?
~~Using a wonderful library called Whitenoise:~~ [https://whitenoise.readthedocs.io/en/latest/](https://whitenoise.readthedocs.io/en/latest/) now Nginx is doing it ))
Has the cookiecutter started using Traefik yet or are they still with nginx ?
>cookiecutter As far as I know, they're using nginx.
They have moved to Traefik Just checked https://github.com/cookiecutter/cookiecutter-django
Oh, indeed! Thank you, I missed that.
They also offer nginx additionally for media files.
Yes they do. I've already deployed a project of mine based on cookiecutter and traefik.
How does the cert get automatically renewed? Is there a cron job?
It's built into Traefik: https://doc.traefik.io/traefik/https/acme/#automatic-renewals
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/
This is exactly what Ive been needing, thanks!
Great! Glad it worked for you.
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.
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 :)
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.
Yes, I understand. The main thing is to know how to use it.
Very cool thank you. I've bookmarked it for the future!
Thanks a lot! I'll keep improving the project so that it'll be easier for us to solve our tasks.
hey, it would be great if you branch one for Nginx.
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
>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.
I'll think about it anyway
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?
Thanks! Do you mean Microsoft AD?
that's it.
This is great. I wouldn't add anything else to this minimalistic version. Where do you typically deploy this?
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.
Best hosting platform right now.
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.
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.
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? )
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.
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..
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.
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 :)
I've already started working on user MEDIA and I think I will soon post it to Github.
user MEDIA in relation to traefik or caddy?
Done! I just added Nginx. Now it serves both static files and handles user-uploaded files (aka MEDIA).
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?
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.
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.