Preset: Nice¶
This preset offers nice configuration defaults.
-
class
uwsgiconf.presets.nice.
Section
(name: str = None, *, touch_reload: Union[str, List[str]] = None, workers: int = None, threads: Union[int, bool] = None, mules: int = None, owner: str = None, log_into: str = None, log_dedicated: bool = None, process_prefix: str = None, ignore_write_errors: bool = None, **kwargs)¶ Basic nice configuration.
Parameters: - name – Section name.
- touch_reload – Reload uWSGI if the specified file or directory is modified/touched.
- workers – Spawn the specified number of workers (processes). Default: workers number equals to CPU count.
- threads – Number of threads per worker or
True
to enable user-made threads support. - mules – Number of mules to spawn.
- owner – Set process owner user and group.
- log_into – Filepath or UDP address to send logs into.
- log_dedicated – If
True
all logging will be handled with a separate thread in master process. - process_prefix – Add prefix to process names.
- ignore_write_errors –
If
True
no annoying SIGPIPE/write/writev errors will be logged, and no related exceptions will be raised.Note
Usually such errors could be seen on client connection cancelling and are safe to ignore.
- kwargs –
-
get_log_format_default
() → str¶ Returns default log message format.
Note
Some params may be missing.
-
classmethod
get_bundled_static_path
(filename: str) → str¶ Returns a full path to a static HTML page file bundled with uwsgiconf.
Parameters: filename – File name to return path to.
- Examples:
- 403.html
- 404.html
- 500.html
- 503.html
-
configure_maintenance_mode
(trigger: Union[str, pathlib.Path], response: str)¶ Allows maintenance mode when a certain response is given for every request if a trigger is set.
Parameters: - trigger – This triggers maintenance mode responses. Should be a path to a file: if file exists, maintenance mode is on.
- response –
Response to to give in maintenance mode.
- Supported:
- File path - this file will be served in response.
- URLs starting with
http
- requests will be redirected there using 302.
This is often discouraged, because it may have search ranking implications.- Prefix
app
will replace your entire app with a maintenance one.
Using this also prevents background tasks registration and execution (including scheduler, timers, signals).- If the value is app - the default maintenance application bundled with uwsgiconf would be used.
- Format
app::<your-module>:<your-app-function>
instructs uwsgiconf to load your function as a maintenance app. E.g.: app::my_pack.my_module:my_func
-
configure_owner
(owner: str = 'www-data')¶ Shortcut to set process owner data.
Parameters: owner – Sets user and group. Default: www-data
.
-
configure_https_redirect
()¶ Enables HTTP to HTTPS redirect.
-
configure_certbot_https
(domain: str, webroot: str, *, address: str = None, allow_shared_sockets: bool = None, http_redirect: bool = False)¶ Enables HTTPS using certificates from Certbot https://certbot.eff.org.
Note
This relies on
webroot
mechanism of Certbot - https://certbot.eff.org/docs/using.html#webrootSample command to get a certificate:
certbot certonly --webroot -w /webroot/path/ -d mydomain.org
Parameters: - domain – Domain name certificates issued for
(the same as in
-d
option in the above command). - webroot – Directory to store challenge files to get and renew the certificate
(the same as in
-w
option in the above command). - address – Address to bind socket to.
- allow_shared_sockets – Allows using shared sockets to bind to privileged ports. If not provided automatic mode is enabled: shared are allowed if current user is not root.
- http_redirect – Redirect HTTP requests to HTTPS if certificates exist.
- domain – Domain name certificates issued for
(the same as in
-
configure_logging_json
()¶ Configures uWSGI output to be json-formatted.
-
class
uwsgiconf.presets.nice.
PythonSection
(name: str = None, *, params_python: dict = None, wsgi_module: str = None, wsgi_callable: Union[str, Callable] = None, embedded_plugins: Optional[bool] = True, require_app: bool = True, threads: Union[bool, int] = True, **kwargs)¶ Basic nice configuration using Python plugin.
Parameters: - name – Section name.
- params_python – See Python plugin basic params.
- wsgi_module –
WSGI application module path or filepath.
- Example:
- mypackage.my_wsgi_module – read from application attr of mypackage/my_wsgi_module.py mypackage.my_wsgi_module:my_app – read from my_app attr of mypackage/my_wsgi_module.py
- wsgi_callable – WSGI application callable name. Default: application.
- embedded_plugins – This indicates whether plugins were embedded into uWSGI, which is the case if you have uWSGI from PyPI.
- require_app – Exit if no app can be loaded.
- threads – Number of threads per worker or
True
to enable user-made threads support. - kwargs –