12đź‘Ť
Should I use one web server or two? The context of this question is
that lots of people recommend using NginX to serve static media files
and Apache to serve the Python, which beckons the following questions:
Why can’t we use just one server. I understand Apache may be a beast
at times, therefore I would suspect people to use NginX to serve BOTH
static media files and python files.
If you currently have no other sites that are already configured in one way or another, or you need some specific features that are mutually exclusive between the various servers, I see no reason for using multiple servers. This just adds unnecessary complexity and configuration.
If using one server, what is better, Apache or NginX.
I am experienced in Apache, but I have heard only good things about NginX.
As with all “which is better” questions this is usually a matter of preference. And to get a specific answer you probably need to ask more specific questions.
If you already have experience with a specific server and you just want to get up an running quickly, then I would suggest going with what you already know for the time being. You can always switch to another web server later.
On the other hand it’s a good opportunity to learn about the alternatives.
tl;dr : I would go for what is easier to configure and manage. Personally I would go for a nginx and gunicorn, mainly because it’s easy and there are plenty of resources available if you should get stuck.
I wouldn’t worry too much about the performance until you actually need to. All staple web servers are tried and tested so it mostly comes down to the requirements of the application and the actual load, which needs monitoring and modeling and testing for fine tuning anyways.
What are the advantages to using FastCGI as opposed to mod_wsgi?
Differences and uses between WSGI, CGI, FastCGI, and mod_python in regards to Python?
articles to read (some old, some new);
- http://gunicorn-docs.readthedocs.org/en/latest/deploy.html
- https://docs.djangoproject.com/en/dev/howto/deployment/
- http://serversforhackers.com/editions/2014/03/25/nginx/
- http://blog.dscpl.com.au/2009/05/blocking-requests-and-nginx-version-of.html
- http://www.thegeekstuff.com/2013/11/nginx-vs-apache/
- http://raspberrywebserver.com/raspberrypicluster/comparing-the-performance-of-nginx-and-apache-web-servers.html
- http://www.bearfruit.org/2013/04/19/reddit-is-melting-our-server-heres-what-we-did-nginx-apache-django-and-mysql/
- In production, Apache + mod_wsgi or Nginx + mod_wsgi?
- http://www.peterbe.com/plog/fcgi-vs-gunicorn-vs-uwsgi
- http://www.aosabook.org/en/nginx.html
- http://c2.com/cgi/wiki?PrematureOptimization
3đź‘Ť
I’m not sure who is recommending to you that you use both Nginx and Apache, but that’s a horrible idea. Whichever you choose, either will simply act as the reverse proxy, serving only static resources and handing everything else off to a subprocess like uwsgi.
I prefer Nginx because it’s light-weight and extremely fast out of the box. Apache can be just as good, but requires building from source and knowing exactly what configuration to use to match Nginx. However, Apache has more features and is a little easier to work with. It’s really up to you and the needs of your application.
However, whichever you choose, you only need one — not both.
- [Django]-Django DRF with oAuth2 using DOT (django-oauth-toolkit)
- [Django]-Django REST Framework – Serializing optional fields
- [Django]-How to drop all tables from the database with manage.py CLI in Django?
3đź‘Ť
I think the best choices is virtualenv, uwsgi and nginx.
I changed all my servers now and I’m really happy with performance.
Here is good tutorial on how to setup you webserver
http://senya.pl/2011/03/sexy-nginx-uwsgi-stack-for-django-with-virtualenv/
- [Django]-Django: sqlite for dev, mysql for prod?
- [Django]-Django viewset has not attribute 'get_extra_actions'
- [Django]-Want to disable signals in Django testing
2đź‘Ť
Question 1) You can use just one server, but for serving static media a solution like lighttpd or nginx will be much faster. I would stick with Apache if you really want to use only one server, it has all the flexibility you need and it is the most common webserver.
Question 2) Depends on your purpose. You can find info here: Deploying Django (fastcgi, apache mod_wsgi, uwsgi, gunicorn)
- [Django]-Django Footer and header on each page with {% extends }
- [Django]-STATIC_ROOT vs STATIC_URL in Django
- [Django]-Django models: get list of id
1đź‘Ť
I tried to follow the suggested link by Nicowernli, but senya.pl was down at that moment.
This seems like a good alternative tutorial….
Gonna try it, just read the first 2 chapters, but seems very complete and really step by step:
- [Django]-CSRF validation does not work on Django using HTTPS
- [Django]-Django Order By Date, but have "None" at end?
- [Django]-Duplicating model instances and their related objects in Django / Algorithm for recusrively duplicating an object
0đź‘Ť
- The less, the better.
- The best way to deploy Django application over Nginx is use uwsgi. It’s pure WSGI and built in supported by new version Nginx.
- [Django]-How to See if a String Contains Another String in Django Template
- [Django]-Django ImportError: cannot import name 'render_to_response' from 'django.shortcuts'
- [Django]-Django model: NULLable field
0đź‘Ť
I have used gunicorn + eventlet as the Python server, and nginx as the reverse proxy with great success. Recently I switched to uWSGI and it seems to be just as good of a solution if not better. I have yet to try apache and Django although I was an apache user prior to using Django. Here is a good write up on getting it all done: http://radtek.ca/blog/django-production-deployment-via-nginx-and-gunicorn-and-virtualenv/
- [Django]-Django template includes slow?
- [Django]-How to assign items inside a Model object with Django?
- [Django]-How do I execute raw SQL in a django migration