Statics

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

Statics.

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.

Note

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

DIR_DOCUMENT_ROOT = 'docroot'

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.

REQUEST_URI = 'uri'

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)
Parameters:
  • static_dir (str|unicode|list[str|unicode]) –

    Check for static files in the specified directory.

    Note

    Use DIR_DOCUMENT_ROOT constant to serve files under DOCUMENT_ROOT.

  • index_file (str|unicode|list[str|unicode]) –

    Search for specified file if a directory is requested.

    Example: index.html

  • mime_file (str|unicode|list[str|unicode]) –

    Set mime types file path to extend uWSGI builtin list.

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

  • skip_ext (str|unicode|list[str|unicode]) –

    Skip specified extension from static file checks.

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

  • transfer_mode (str|unicode) –

    Set static file serving (transfer) mode.

    See .transfer_modes.

    Note

    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).

Parameters:
  • mountpoint (str|unicode) –
  • target (str|unicode) –
  • 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.

Parameters:
  • criterion (str|unicode) –

    Criterion (subject) to base expiration on.

    See .expiration_criteria.

  • value (str|unicode|list[str|unicode]) –

    Value to test criteria upon.

    Note

    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.

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