uWSGI is a versatile application server for serving Python web applications. It is often used in conjunction with web servers like Nginx or Apache to handle requests efficiently.
To install uWSGI, you can use pip:
pip install uwsgi
Alternatively, you can install it using your system’s package manager. For example, on Debian-based systems:
sudo apt-get install uwsgi
sudo apt-get install uwsgi-plugin-python3
uWSGI can be configured using a configuration file, command-line options, or environment variables. Here is an example configuration file (uwsgi.ini
):
[uwsgi]
module = myapp:app
master = true
processes = 5
socket = 127.0.0.1:8000
chmod-socket = 660
vacuum = true
die-on-term = true
To run uWSGI with the configuration file:
uwsgi --ini uwsgi.ini
You can also run uWSGI directly from the command line:
uwsgi --http :8000 --module myapp:app
To use uWSGI with Nginx, you need to configure Nginx to pass requests to the uWSGI server. Here is an example Nginx configuration:
server {
listen 80;
server_name example.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
}
}
uWSGI provides various tools for monitoring and managing your application. You can use the uwsgi
command to check the status of your application, reload it, or stop it.
To check the status:
uwsgi --connect-and-read :8000
To reload the application:
uwsgi --reload /path/to/uwsgi.pid
To stop the application:
uwsgi --stop /path/to/uwsgi.pid