Standalone Python web server and/or nginx

2019-04-12 15:01发布

问题:

So I've done some reading about Python web frameworks (or servers?), mostly Tornado and Bottle but also FAPWS3, and there are still some grey areas.

First, these three web frameworks are all said to be fast, yet they all include a web server written in Python (except FAPWS3) which should be put behind nginx/Apache. Isn't this reducing the performance? I mean, we know that Python is much slower than C, why not only use nginx, or at worst, only the included Python web server?

回答1:

First of, Tornado and FAPWS3 are web servers, while Bottle is a web framework. Those belong to completely different categories.

Web frameworks are usually run as a WSGI server behind a HTTP ("web") proxy. The HTTP server included in most frameworks is only there for fast development and deployment and easy deployment on sites where high efficiency doesn't matter.

The idea is basically that the HTTP Server (Apache/Lighttpd/Nginx/Tornado/FAPWS3 etc) is very good at understanding HTTP and serving static files from the disk. The dynamic content on the other hand is generated by a Python server using a web framework like Bottle/Flask/web.py/Pylons/etc. The document produced by the web framework is then sent back to the HTTP server over WSGI, put in a HTTP Response and sent to the client.