Python servers configuration

uWSGI, Gunicorn and Nginx configuration

Note

This page applies to the legacy Python deployment mode (without uv.lock). Native uv deployments manage their own HTTP server and do not use uWSGI, Gunicorn, or Nginx.

uWSGI, Gunicorn and Nginx settings can be configured by setting environment variables.

uWSGI

NameDescriptionDefault
HARAKIRITimeout (in seconds) after which an unresponsive process is killed180
WSGI_BUFFER_SIZEMaximal size (in bytes) for the headers of a request4096
WSGI_POST_BUFFERINGBuffer size (in bytes) for uploads4096
WSGI_WORKERSNumber of workersdepends on the scaler
WSGI_THREADSNumber of threads per workerdepends on the scaler

You can inject additional uWSGI configuration directives with CC_UWSGI_EXTRA_CONFIG. To disable the file wrapper, set CC_UWSGI_DISABLE_FILE_WRAPPER to true.

uWSGI asynchronous/non-blocking modes

To enable uWSGI asynchronous mode, you can use these two environment variables:

Gunicorn

NameDescriptionDefault
CC_GUNICORN_WORKER_CLASSType of worker to use. Available workerssync
CC_GUNICORN_TIMEOUTGunicorn timeout (in seconds)30
CC_GUNICORN_LOGLEVELGunicorn log levelinfo

Nginx

NameDescriptionDefault
NGINX_READ_TIMEOUTResponse timeout in seconds (similar to HARAKIRI)300
ENABLE_GZIP_COMPRESSIONEnable gzip compression (on, yes, or true)
GZIP_TYPESThe mime types to gziptext/plain text/css text/xml text/javascript application/json application/xml application/javascript image/svg+xml

Basic authentication

If you need basic authentication, you can enable it using environment variables. Set CC_HTTP_BASIC_AUTH variable to your own login:password pair. If you need to allow access to multiple users, you can create additional environment CC_HTTP_BASIC_AUTH_n (where n is a number) variables.

Nginx optional configuration with clevercloud/http.json

Nginx settings can be configured further in clevercloud/http.json. All its fields are optional.

  • languages: configure a default language and redirections
  • error_pages: configure custom files for error pages
  • force_https: automatically redirect HTTP traffic to HTTPS
  • aliases: set up redirections
  • charset: force a specific charset
{
    "languages": {
        "default": {"rewrite": "en"},
        "fr": {"rewrite": "en"}
    },
    "error_pages": {
        "404": "path/to/page"
    },
    "force_https": true,
    "aliases": {
        "/path": "redirection"
    },
    "charset": "latin-1"
}

Manage static files

To enable Nginx to serve your static resources, you have to set two environment variables.

NameDescription
STATIC_FILES_PATHDirectory where your static files are stored (absolute path relative to the application root)
STATIC_URL_PREFIXURL path under which you want to serve static files (e.g. /public)

You can also use a Filesystem Bucket to store your static files.

Warning

Setting STATIC_URL_PREFIX to / makes static files override the default application location. The static configuration replaces the main location / block in Nginx, and your application becomes accessible only through the @app fallback.

Static files example

Here is how to serve static files, the test.png being the static file you want to serve:

├── <app_root>
│   ├── flask-app.py
│   ├── static
│   │   └── test.png
│   └── requirements.txt

Using the environment variables STATIC_FILES_PATH=static/ and STATIC_URL_PREFIX=/public the test.png file will be accessed under: https://<domain.tld>/public/test.png.

Last updated on

Did this documentation help you ?