Skip to content

Statics

Classes

Statics

Statics(*args, **kwargs)

OptionsGroup

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

.DIR_DOCUMENT_ROOT = 'docroot'

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


name

.name: str = ''

Name to represent the group.


plugin

.plugin: bool | str = False

Indication this option group belongs to a plugin.


add_expiration_rule

1
2
3
4
5
6
.add_expiration_rule(
    criterion: str,  # (1)!
    value: Strlist,  # (2)!
    timeout: int,  # (3)!
    use_mod_time: bool = False,  # (4)!
)
  1. Criterion (subject) to base expiration on.

    1
    See ``.expiration_criteria``.
    
  2. Value to test criteria upon.

    1
    .. note:: Usually a regular expression.
    
  3. Number of seconds to expire after.

  4. Base on file modification time instead of the current time.

Adds statics expiration rule based on a criterion.


register_static_map

1
2
3
4
5
6
.register_static_map(
    mountpoint: str, 
    target: str, 
    retain_resource_path: bool = False,  # (1)!
    safe_target: bool = False,  # (2)!
)
  1. Append the requested resource to the docroot.

    1
    2
    3
    4
    5
    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``
    
  2. Skip security checks if the file is under the specified path.

    1
    2
    3
    Whether to consider resolved (real) target a safe one to serve from.
    
    * <http://uwsgi.readthedocs.io/en/latest/StaticFiles.html#security>
    

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


set_basic_params

1
2
3
4
5
6
7
.set_basic_params(
    static_dir: Strlist = None,  # (1)!
    index_file: Strlist = None,  # (2)!
    mime_file: Strlist = None,  # (3)!
    skip_ext: Strlist = None,  # (4)!
    transfer_mode: str | None = None,  # (5)!
)
  1. Check for static files in the specified directory.

    1
    .. note:: Use ``DIR_DOCUMENT_ROOT`` constant to serve files under ``DOCUMENT_ROOT``.
    
  2. Search for specified file if a directory is requested.

    1
    Example: ``index.html``
    
  3. Set mime types file path to extend uWSGI builtin list.

    1
    Default: ``/etc/mime.types`` or ``/etc/apache2/mime.types``.
    
  4. Skip specified extension from static file checks.

    1
    Example: add ``.php`` to not serve it as static.
    
  5. Set static file serving (transfer) mode.

    1
    2
    3
    See ``.transfer_modes``.
    
    .. note:: Another option is to specify ``count_offload`` in ``.workers.set_thread_params()``.
    

set_paths_caching_params

1
2
3
4
.set_paths_caching_params(
    timeout: int | None = None, 
    cache_name: str | None = None
)

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


expiration_criteria

.expiration_criteria()

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


FILENAME
.FILENAME = 'filename'

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


MIME_TYPE
.MIME_TYPE = 'type'

Allows setting the Expires header for the specified MIME type.


PATH_INFO
.PATH_INFO = 'path-info'

Allows setting the Expires header for the specified PATH_INFO pattern.


REQUEST_URI
.REQUEST_URI = 'uri'

Allows setting the Expires header for the specified REQUEST_URI pattern.


transfer_modes

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


ACCEL_REDIRECT
.ACCEL_REDIRECT = 'x-accel-redirect'

Use X-Accel-Redirect mode. Nginx.


SENDFILE
.SENDFILE = 'x-sendfile'

Use X-Sendfile mode. Apache.