What IS uWsgi
Short introduction to uWSGI server and architecture
The uWSGI project aims at developing a full stack for building hosting services. Application servers (for various programming languages and protocols), proxies, process managers, and monitors are all implemented using a common API and a common configuration style. Thanks to its pluggable architecture it can be extended to support more platforms and languages.
    uWSGI - official documentation

uWSGI Components

    The Core (implements configuration, processes management, sockets creation, monitoring, logging, shared memory areas, ipc, cluster membership)
    Request plugins (implement application server interfaces for various languages and platforms: WSGI, PSGI, Rack, Lua WSAPI, CGI, PHP, Go …)
    Gateways (implement load balancers, proxies and routers)

Quickstart for Python

This quickstart will show you how to deploy simple WSGI applications and common web frameworks. In order to start using uWSGI we need the build-essential python-dev tooling.
Install on Debian-based distro
1
$ apt-get install build-essential python-dev
Copied!
Install on CentOS distro
1
$ yum install build-essential python-dev
Copied!

Install uWSGI

Before installing uWSGI module, make sure the workstation has the Python development installed.
1
$ # Ubuntu, Debian
2
$ sudo apt-get install python-dev # for python2.x installs
3
$ sudo apt-get install python3-dev # for python3.x installs
4
$
5
$ # CentOS, RHEL
6
$ sudo yum install python-devel # for python2.x installs
7
$ sudo yum install python3-devel # for python3.x installs
8
$
9
$ # Fedora
10
sudo dnf install python2-devel # for python2.x installs
11
sudo dnf install python3-devel # for python3.x installs
Copied!
uWSGI Via PIP
1
$ pip install uwsgi
Copied!
Using the network installer
1
$ curl http://uwsgi.it/install | bash -s default /tmp/uwsgi
Copied!

Simple uWSGI app

Let’s start with a simple “Hello World” example:
1
def application(env, start_response):
2
start_response('200 OK', [('Content-Type','text/html')])
3
return [b"Hello World"]
Copied!
Let's save this minimal app as hitme.py
As you can see, it is composed of a single Python function. It is called “application” as this is the default function that the uWSGI Python loader will search for.
Deploy it on HTTP port 9090
1
$ uwsgi --http :9090 --wsgi-file hitme.py
Copied!
In case we need monitoring, the stats subsystem allows you to export uWSGI’s internal statistics as JSON:
1
$ uwsgi --http :9090 --wsgi-file hitme.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191
Copied!
By visiting port 9090 in the browser, we should see Hello World message served by uWSGI.

uWSGI Resources

Last modified 5mo ago