class uwsgiconf.options.statics.Statics(*args, **kwargs)


Unfortunately you cannot live without serving static files via some protocol (HTTP, SPDY or something else). Fortunately uWSGI has a wide series of options and micro-optimizations for serving static files.


This subsystem automatically honours the If-Modified-Since HTTP request header.


Used to check for static files in the requested DOCUMENT_ROOT. Pass into static_dir.

class expiration_criteria

Expiration criteria (subjects) to use with .add_expiration_rule().

FILENAME = 'filename'

Allows setting the Expires header for the specified file name pattern.

MIME_TYPE = 'type'

Allows setting the Expires header for the specified MIME type.

PATH_INFO = 'path-info'

Allows setting the Expires header for the specified PATH_INFO pattern.


Allows setting the Expires header for the specified REQUEST_URI pattern.

class transfer_modes

File transfer (serving) modes.

With this, uWSGI will only generate response headers and the web server will be delegated to transferring the physical file.

SENDFILE = 'x-sendfile'

Use X-Sendfile mode. Apache.

ACCEL_REDIRECT = 'x-accel-redirect'

Use X-Accel-Redirect mode. Nginx.

set_basic_params(*, static_dir=None, index_file=None, mime_file=None, skip_ext=None, transfer_mode=None)
  • static_dir (str|list[str]) –

    Check for static files in the specified directory.


    Use DIR_DOCUMENT_ROOT constant to serve files under DOCUMENT_ROOT.

  • index_file (str|list[str]) –

    Search for specified file if a directory is requested.

    Example: index.html

  • mime_file (str|list[str]) –

    Set mime types file path to extend uWSGI builtin list.

    Default: /etc/mime.types or /etc/apache2/mime.types.

  • skip_ext (str|list[str]) –

    Skip specified extension from static file checks.

    Example: add .php to not serve it as static.

  • transfer_mode (str) –

    Set static file serving (transfer) mode.

    See .transfer_modes.


    Another option is to specify count_offload in .workers.set_thread_params().

register_static_map(mountpoint, target, *, retain_resource_path=False, safe_target=False)

Allows mapping mountpoint to a static directory (or file).

  • mountpoint (str) –
  • target (str) –
  • retain_resource_path (bool) –

    Append the requested resource to the docroot.

    Example: if /images maps to /var/www/img requested /images/logo.png will be served from:

    • True: /var/www/img/images/logo.png
    • False: /var/www/img/logo.png
  • safe_target (bool) –

    Skip security checks if the file is under the specified path.

    Whether to consider resolved (real) target a safe one to serve from.

add_expiration_rule(criterion, value, *, timeout, use_mod_time=False)

Adds statics expiration rule based on a criterion.

  • criterion (str) –

    Criterion (subject) to base expiration on.

    See .expiration_criteria.

  • value (str|list[str]) –

    Value to test criteria upon.


    Usually a regular expression.

  • timeout (int) – Number of seconds to expire after.
  • use_mod_time (bool) – Base on file modification time instead of the current time.
set_paths_caching_params(*, timeout=None, cache_name=None)

Use the uWSGI caching subsystem to store mappings from URI to filesystem paths.

  • timeout (int) – Amount of seconds to put resolved paths in the uWSGI cache.
  • cache_name (str) – Cache name to use for static paths.