⚠️ PROJECT STATUS: MAINTENANCE MODE
uWSGI is in maintenance mode (announced 2024). The project receives only bugfixes and updates for new language APIs. Maintainer response times on GitHub issues/PRs are slow.
- name: Install uWSGI
hosts: uwsgi
become: true
vars:
uwsgi_config_dir: /etc/uwsgi
uwsgi_apps_dir: /etc/uwsgi/apps-available
uwsgi_user: www-data
uwsgi_group: www-data
tasks:
- name: Warn about maintenance mode
ansible.builtin.debug:
msg: |
⚠️ UWSGI MAINTENANCE MODE
- Project receives only bugfixes (since 2024)
- Slow maintainer response on issues/PRs
- Consider Gunicorn/Uvicorn for new projects
- name: Install uWSGI package (Debian/Ubuntu)
ansible.builtin.apt:
name:
- uwsgi
- uwsgi-plugin-python3
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install uWSGI package (RHEL family - EPEL)
ansible.builtin.dnf:
name:
- uwsgi
- uwsgi-plugin-python3
state: present
when: ansible_os_family == "RedHat"
failed_when: false
- name: Create configuration directory
ansible.builtin.file:
path: "{{ uwsgi_config_dir }}"
state: directory
mode: "0755"
owner: root
group: root
- name: Create apps-available directory
ansible.builtin.file:
path: "{{ uwsgi_apps_dir }}"
state: directory
mode: "0755"
owner: root
group: root
- name: Create run directory
ansible.builtin.file:
path: /var/run/uwsgi
state: directory
mode: "0775"
owner: "{{ uwsgi_user }}"
group: "{{ uwsgi_group }}"
- name: Create log directory
ansible.builtin.file:
path: /var/log/uwsgi
state: directory
mode: "0755"
owner: "{{ uwsgi_user }}"
group: adm
- name: Enable and start uWSGI service
ansible.builtin.systemd:
name: uwsgi
state: started
enabled: true
failed_when: false
- name: Verify uWSGI binary
ansible.builtin.command: "uwsgi --version"
register: uwsgi_version
changed_when: false
failed_when: false
- name: Display uWSGI version
ansible.builtin.debug:
var: uwsgi_version.stdout
For systems without packages or for latest version:
- name: Install uWSGI via pip
hosts: uwsgi
become: true
vars:
uwsgi_venv_dir: /opt/myapp/venv
uwsgi_config_dir: /etc/uwsgi
tasks:
- name: Install prerequisites
ansible.builtin.package:
name:
- python3
- python3-venv
- python3-dev
- build-essential
state: present
- name: Create virtual environment
ansible.builtin.command:
cmd: "python3 -m venv {{ uwsgi_venv_dir }}"
args:
creates: "{{ uwsgi_venv_dir }}/bin/activate"
- name: Install uWSGI in venv
ansible.builtin.pip:
name: uwsgi
virtualenv: "{{ uwsgi_venv_dir }}"
virtualenv_command: "{{ uwsgi_venv_dir }}/bin/python -m venv"
- name: Verify uWSGI installation
ansible.builtin.command: "{{ uwsgi_venv_dir }}/bin/uwsgi --version"
register: uwsgi_version
changed_when: false
- name: Display uWSGI version
ansible.builtin.debug:
var: uwsgi_version.stdout
Complete deployment with application and Nginx:
- name: Deploy Python app with uWSGI and Nginx
hosts: app_servers
become: true
vars:
app_name: myapp
app_user: myapp
app_group: myapp
app_dir: /var/www/myapp
uwsgi_socket: 127.0.0.1:8000
uwsgi_processes: 4
nginx_server_name: example.com
tasks:
- name: Create application user
ansible.builtin.user:
name: "{{ app_user }}"
group: "{{ app_group }}"
system: true
shell: /usr/sbin/nologin
create_home: false
- name: Install dependencies
ansible.builtin.package:
name:
- python3
- python3-venv
- python3-dev
- build-essential
- nginx
- uwsgi
- uwsgi-plugin-python3
state: present
- name: Create application directory
ansible.builtin.file:
path: "{{ app_dir }}"
state: directory
mode: "0755"
owner: "{{ app_user }}"
group: "{{ app_group }}"
- name: Create virtual environment
ansible.builtin.command:
cmd: "python3 -m venv {{ app_dir }}/venv"
args:
creates: "{{ app_dir }}/venv/bin/activate"
- name: Install application dependencies
ansible.builtin.pip:
requirements: "{{ app_dir }}/requirements.txt"
virtualenv: "{{ app_dir }}/venv"
notify: restart uwsgi
- name: Deploy uWSGI configuration
ansible.builtin.template:
src: templates/uwsgi.ini.j2
dest: "/etc/uwsgi/apps-available/{{ app_name }}.ini"
mode: "0644"
notify: restart uwsgi
- name: Enable uWSGI app
ansible.builtin.file:
src: "/etc/uwsgi/apps-available/{{ app_name }}.ini"
dest: "/etc/uwsgi/apps-enabled/{{ app_name }}.ini"
state: link
notify: restart uwsgi
- name: Deploy Nginx configuration
ansible.builtin.template:
src: templates/nginx_uwsgi.j2
dest: "/etc/nginx/sites-available/{{ app_name }}"
mode: "0644"
notify: restart nginx
- name: Enable Nginx site
ansible.builtin.file:
src: "/etc/nginx/sites-available/{{ app_name }}"
dest: "/etc/nginx/sites-enabled/{{ app_name }}"
state: link
notify: restart nginx
- name: Enable and start services
ansible.builtin.systemd:
name: "{{ item }}"
state: started
enabled: true
loop:
- uwsgi
- nginx
handlers:
- name: restart uwsgi
ansible.builtin.systemd:
name: uwsgi
state: restarted
- name: restart nginx
ansible.builtin.systemd:
name: nginx
state: restarted
# templates/uwsgi.ini.j2
[uwsgi]
module = {{ app_name }}:app
master = true
processes = {{ uwsgi_processes }}
socket = {{ uwsgi_socket }}
chmod-socket = 660
vacuum = true
die-on-term = true
pidfile = /var/run/uwsgi/{{ app_name }}.pid
logto = /var/log/uwsgi/{{ app_name }}.log
home = {{ app_dir }}/venv
chdir = {{ app_dir }}
# templates/nginx_uwsgi.j2
server {
listen 80;
server_name {{ nginx_server_name }};
location / {
include uwsgi_params;
uwsgi_pass {{ uwsgi_socket }};
uwsgi_param Host $host;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Proto $scheme;
}
location /static {
alias {{ app_dir }}/static;
expires 30d;
}
}
| Distribution | Status | Version |
|---|---|---|
| Debian 12/13 | ✅ Available | Varies |
| Ubuntu 22.04/24.04 | ✅ Available | Varies |
| RHEL 9 | ✅ EPEL | 2.0.31 |
| RHEL 10 | ⚠️ Unclear | Use pip |
| Method | Pros | Cons |
|---|---|---|
| pip | Latest version, cross-platform | Manual updates |
| Package | System integration, auto-updates | May be outdated |
⚠️ Maintenance Mode Warning
Security patches may be slower due to maintenance mode status.
See uWSGI Security and uWSGI Hardening for security guidance.
We develop tailored automation solutions for:
Let’s discuss your requirements: office@linux-server-admin.com | Contact