Skip to content

Instantly share code, notes, and snippets.

@dungvtdev
Created September 1, 2016 04:59
Show Gist options
  • Save dungvtdev/083d71ebbeafc62a0d3894b502b6bf57 to your computer and use it in GitHub Desktop.
Save dungvtdev/083d71ebbeafc62a0d3894b502b6bf57 to your computer and use it in GitHub Desktop.

WSGI server, Web server

Links: https://www.fullstackpython.com/wsgi-servers.html https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface

Architecture call object request executed request wsgi application/framework <-------> wsgi server <------> web server <-----> client [falcon...] [gunicorn...] [nginx...]

webserver/wsgi server pass environment information to wsgi application

WSGI server

  • WSGI stands for Web Server Gateway Interface.
  • WSGI server implements the web server side of the WSGI interface for running Python web applications.
  • WSGI server simply invokes a callable object on the WSGI application as defined by the PEP 3333 standard.
  • WSGI is a middleware components, perform functions:
    • Routing a request to different application objects based on the target URL, after changing the environment variables accordingly.
    • Allowing multiple applications or frameworks to run side-by-side in the same process
    • Load balancing and remote processing, by forwarding requests and responses over a network
    • Performing content post-processing, such as applying XSLT stylesheets

Flexibility

Application developers can swap out web stack components for others. For example, a developer can switch from Green Unicorn to uWSGI without modifying the application or framework that implements WSGI

Promote scaling

Serving thousands of requests for dynamic content at once is the domain of WSGI servers, not frameworks. WSGI servers handle processing requests from the web server and deciding how to communicate those requests to an application framework's process. The segregation of responsibilities is important for efficiently scaling web traffic.

ex: green unicorn, uWSGI, mod_wsgi, CherryPy...

WebServer

from http://nginx.org/en/

Basic features

  • Serving static and index files, autoindexing; open file descriptor cache;
  • Accelerated reverse proxying with caching; load balancing and fault tolerance;
  • Accelerated support with caching of FastCGI, uwsgi, SCGI, and memcached servers; load balancing and fault tolerance;
  • Modular architecture. Filters include gzipping, byte ranges, chunked responses, XSLT, SSI, and image transformation filter. - - Multiple SSI inclusions within a single page can be processed in parallel if they are handled by proxied or FastCGI/uwsgi/SCGI servers;
  • SSL and TLS SNI support;
  • Support for HTTP/2 with weighted and dependency-based prioritization.

Ex: nginx, apache...

Wrappers The server or gateway invokes the application callable once for each request it receives from an HTTP client, that is directed at the application.

Currently wrappers are available for FastCGI, CGI, SCGI, AJP (using flup), twisted.web, Apache (using mod_wsgi or mod_python), Nginx (using ngx_http_uwsgi_module), and Microsoft IIS (using WFastCGI, isapi-wsgi, PyISAPIe, or an ASP gateway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment