Differences between revisions 6 and 20 (spanning 14 versions)
Revision 6 as of 2022-09-26 17:41:50
Size: 1671
Comment:
Revision 20 as of 2023-04-22 20:28:28
Size: 1780
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Python UWSGI = = Uwsgi =
Line 3: Line 3:
'''`uWSGI`''' is a [[Protocols/UWSGI]] server. Although it is written in [[C]], it's more commonly used by [[Python]] projects. '''uWSGI''' is a [[Protocols/CGI#Web_Server_Gateway_Interface|WSGI]] server. Although it is written in [[C]], it's more commonly used by [[Python]] projects. There is an official Python module.
Line 13: Line 13:
Most Linux operating systems offer both the server and the Python plugin as a package. Try installing `uswgi` and `uwsgi-python3`, or `uwsgi-python` for the Python 2 version.



=== Alpine Linux ===

If using Python 2, note that '''Alpine Linux''' has [[https://alpinelinux.org/posts/Alpine-3.11.0-released.html|dropped support]] for the corresponding software. The last version to offer a `uwsgi-python` package is 3.10.

For [[Docker/Dockerfile|Dockerfiles]], consider the below a template:

{{{
FROM alpine:3.10
RUN apk add python uwsgi uwsgi-python

RUN addgroup -S -g 82 www-data && adduser -S -u 82 -D -h /var/www -s /sbin/nologin www-data
COPY --chown=www-data:www-data local/path/to/app /app
WORKDIR /app

EXPOSE 9000
ENTRYPOINT ["/usr/sbin/uwsgi"]
CMD ["--ini", "/app/uwsgi.ini"]
}}}
Most [[Linux]] distributions offer both the server and the Python plugin as a package. Try installing `uswgi` and `uwsgi-python3`, or `uwsgi-python` for the Python 2 version.
Line 42: Line 21:
`uWSGI` requires a configuration file to run, typically named `uwsgi.ini`. A basic one looks like: `uwsgi` requires a configuration file to run, typically named `uwsgi.ini`.
Line 61: Line 40:
The `wsgi-file` is the Python program that will be served. The `wsgi-file` is the WSGI script that will be served.
Line 67: Line 46:
If exposing the server over a [[Linux/Networking|Unix socket]] instead of a port, try: If exposing the server over a [[Linux/Networking#Unix_Sockets|Unix socket]] instead of a port, try:
Line 74: Line 53:
----



== Usage ==



=== Nginx ===

See [[Nginx/Uwsgi|here]] for details.



=== Containers ===

If using Python 2, note that [[Linux/Alpine|Alpine Linux]] has [[https://alpinelinux.org/posts/Alpine-3.11.0-released.html|dropped support]] for the corresponding software. The last version to offer a `uwsgi-python` package is 3.10.

The below image recipe can be used.

{{{
FROM alpine:3.10
RUN apk add python uwsgi uwsgi-python

RUN addgroup -S -g 82 www-data && adduser -S -u 82 -D -h /var/www -s /sbin/nologin www-data
COPY --chown=www-data:www-data local/path/to/app /app
WORKDIR /app

EXPOSE 9000
ENTRYPOINT ["/usr/sbin/uwsgi"]
CMD ["--ini", "/app/uwsgi.ini"]
}}}

Uwsgi

uWSGI is a WSGI server. Although it is written in C, it's more commonly used by Python projects. There is an official Python module.


Installation

Most Linux distributions offer both the server and the Python plugin as a package. Try installing uswgi and uwsgi-python3, or uwsgi-python for the Python 2 version.


Configuration

uwsgi requires a configuration file to run, typically named uwsgi.ini.

[uwsgi]
uid = www-data
gid = www-data
socket = :9000
plugin = python

chdir = /app/example.com
wsgi-file = /app/example.com/example.wsgi

master
workers = 3
max-requests = 200
harakiri = 60
die-on-term

The wsgi-file is the WSGI script that will be served.

Unix Sockets

If exposing the server over a Unix socket instead of a port, try:

socket = /app/example.com/example.sock
chmod-socket = 660


Usage

Nginx

See here for details.

Containers

If using Python 2, note that Alpine Linux has dropped support for the corresponding software. The last version to offer a uwsgi-python package is 3.10.

The below image recipe can be used.

FROM alpine:3.10
RUN apk add python uwsgi uwsgi-python

RUN addgroup -S -g 82 www-data && adduser -S -u 82 -D -h /var/www -s /sbin/nologin www-data
COPY --chown=www-data:www-data local/path/to/app /app
WORKDIR /app

EXPOSE 9000
ENTRYPOINT ["/usr/sbin/uwsgi"]
CMD ["--ini", "/app/uwsgi.ini"]


CategoryRicottone

Python/Uwsgi (last edited 2023-04-22 20:28:28 by DominicRicottone)