5

I've been developing a simple MVP application, and it's time to deploy it to my production server for more thorough outside testing. It will never get a heavy traffic load, it's just something I need a small group of users to test.

Now I've always gone with three layers. Nginx/Apache > Guncicorn/CherryPy/etc > Flask/Django/Pyramid/Bottle/etc

I KNOW this is the convential wisdom. But I've never actually taken the time to ask why. What am I setting all of these up for?

Ryan
  • 993
  • 1
  • 9
  • 17
  • What alternatives are you comparing that to? If it's just for testing and you don't care about performance and security risks you could use the default server built in to things like Bottle. – BrenBarn Aug 17 '15 at 03:38
  • This is partially explained in http://stackoverflow.com/questions/14814201/can-i-serve-multiple-clients-using-just-flask-app-run-as-standalone. Surprised you don't have a database layer. I figure its usually important and would have it together with a fast multithreaded web server and a web framework. There is a trend to replace the web server with a multiprocessing async IO framework such as Akka (actors) that is used, for example, with Play (web framework) in the TypeSafe stack. –  Aug 17 '15 at 03:48
  • 1
    Just use *CherryPy* as a framework and roll it out on its own as HTTP server, which is okay for low traffic. The fewer moving parts, the better. When traffic increases or advanced features need, you can put *nginx* in front of it, as both speak HTTP. – saaj Aug 17 '15 at 11:23
  • 1
    I think this question is valid, the aim is on why we need the middleware, each has its own purpose, (a web server and wsgi) when a flask app could be good enough for testing or dev cases. – betolink Sep 10 '15 at 01:25

1 Answers1

2

The Django docs have this to say about the included dev server:

We’ve included this with Django so you can develop things rapidly, without having to deal with configuring a production server – such as Apache – until you’re ready for production.

Now’s a good time to note: don’t use this server in anything resembling a production environment. It’s intended only for use while developing. (We’re in the business of making Web frameworks, not Web servers.)

The two advantages of Apache/Nginx over the dev server that come to mind immediately:

  • Django dev server isn't designed with security in mind. Apache/Nginx, being designed to be exposed over the network, have had (and continue to have) effort put into finding/fixing vulnerabilities that the Django dev server just hasn't had.
  • A lot of the requests you serve will be static files (images, JS, CSS). Nginx and Apache are going to be far more efficient in serving these assets than a server written in Python.
chucksmash
  • 5,777
  • 1
  • 32
  • 41
  • So why not just aim nginx straight at django? why the middleware? – Ryan Aug 17 '15 at 03:44
  • MIddleware has a specific meaning that doesn't really fit here. I assume you are referring to uWSGI/Gunicorn. One benefit: process management and monitoring. A uWSGI-managed server process that crashes will be replaced automatically. If you are just running the dev server, your production site is now down. – chucksmash Aug 17 '15 at 03:56
  • Fair enough, i'm not really sure what the appropriate term would be (which is why i'm here asking the question, to be fair). Process management? Monitoring? Isn't that basically the job of whatever i'm using to keep the process running (systemd, or what have you) – Ryan Aug 17 '15 at 04:00
  • I suppose you'd call them your application servers. – chucksmash Aug 17 '15 at 04:03