Why do I need to use a web server, middleware, etc

2019-05-11 10:28发布

问题:

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?

回答1:

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.