Configuration logic — uWSGI 2.0 documentation (original) (raw)

Starting from 1.1 certain logic constructs are available.

The following statements are currently supported:

Each of these statements exports a context value you can access with the special placeholder %(_). For example, the “for” statement sets %(_) to the current iterated value.

Warning

Recursive logic is not supported and will cause uWSGI to promptly exit.

for

For iterates over space-separated strings. The following three code blocks are equivalent.

[uwsgi] master = true ; iterate over a list of ports for = 3031 3032 3033 3034 3035 socket = 127.0.0.1:%(_) endfor = module = helloworld

3031 3032 3033 3034 3035 127.0.0.1:%(_) helloworld

uwsgi --for="3031 3032 3033 3034 3035" --socket="127.0.0.1:%(_)" --endfor --module helloworld

Note that the for-loop is applied to each line inside the block separately, not to the block as a whole. For example, this:

[uwsgi] for = a b c socket = /var/run/%().socket http-socket = /var/run/%()-http.socket endfor =

is expanded to:

[uwsgi] socket = /var/run/a.socket socket = /var/run/b.socket socket = /var/run/c.socket http-socket = /var/run/a-http.socket http-socket = /var/run/b-http.socket http-socket = /var/run/c-http.socket

if-env

Check if an environment variable is defined, putting its value in the context placeholder.

[uwsgi] if-env = PATH print = Your path is %(_) check-static = /var/www endif = socket = :3031

if-exists

Check for the existence of a file or directory. The context placeholder is set to the filename found.

[uwsgi] http = :9090 ; redirect all requests if a file exists if-exists = /tmp/maintenance.txt route = .* redirect:/offline endif =

if-file

Check if the given path exists and is a regular file. The context placeholder is set to the filename found.

python :8080 settings.py django.core.handlers.wsgi:WSGIHandler()

if-dir

Check if the given path exists and is a directory. The context placeholder is set to the filename found.

uwsgi: socket: 4040 processes: 2 if-dir: config.ru rack: %(_) endif:

if-opt

Check if the given option is set, or has a given value. The context placeholder is set to the value of the option reference.

To check if an option was set, pass just the option name to if-opt.

uwsgi: cheaper: 3 if-opt: cheaper print: Running in cheaper mode, with initially %(_) processes endif:

To check if an option was set to a specific value, passoption-name=value to if-opt.

uwsgi:

Set busyness parameters if it was chosen

if-opt: cheaper-algo=busyness cheaper-busyness-max: 25 cheaper-busyness-min: 10 endif:

Due to the way uWSGI parses its configs, you can only refer to options that uWSGI has previously seen. In particular, this means: