5.8 KiB
Configuring Piku via ENV
You can configure deployment settings by placing special variables in an ENV file deployed with your app.
Runtime Settings
PIKU_AUTO_RESTART(boolean, defaults totrue): Piku will restart all workers every time the app is deployed. You can set it to0/falseif you prefer to deploy first and then restart your workers separately.
Python
PYTHON_VERSION(int): Forces Python 3
Node
NODE_VERSION: installs a particular version of node for your app ifnodeenvis found on the path. Optional; if not specified, the system-wide node package is used.
NOTE: you will need to stop and re-deploy the app to change the
nodeversion in a running app.
Network Settings
BIND_ADDRESS: IP address to which your app will bind (typically127.0.0.1)PORT: TCP port for your app to listen in (if deploying your own web listener).DISABLE_IPV6(boolean): if set totrue, it will remove IPv6-specific items from thenginxconfig, which will accept only IPv4 connections
uWSGI Settings
UWSGI_MAX_REQUESTS(integer): set themax-requestsoption to determine how many requests a worker will receive before it's recycled.UWSGI_LISTEN(integer): set thelistenqueue size.UWSGI_PROCESSES(integer): set theprocessescount.UWSGI_ENABLE_THREADS(boolean): set theenable-threadsoption.UWSGI_LOG_MAXSIZE(integer): set thelog-maxsize.UWSGI_LOG_X_FORWARDED_FOR(boolean): set thelog-x-forwarded-foroption.UWSGI_GEVENT: enable the Python 2geventpluginUWSGI_ASYNCIO(integer): enable the Python 2/3asyncioplugin and set the number of tasksUWSGI_INCLUDE_FILE: a uwsgi config file in the app's dir to include - useful for including custom uwsgi directives.UWSGI_IDLE(integer): set thecheap,idleanddie-on-idleoptions to have workers spawned on demand and killed after n seconds of inactivity.
NOTE:
UWSGI_IDLEapplies to all the workers, so if you haveUWSGI_PROCESSESset to 4, they will all be killed simultaneously. Support for progressive scaling of workers viacheaperand similar uWSGI configurations will be added in the future.
nginx Settings
NGINX_SERVER_NAME: set the virtual host name associated with your appNGINX_STATIC_PATHS(string, comma separated list): set an array of/url:pathvalues that will be served directly bynginxNGINX_CLOUDFLARE_ACL(boolean, defaults tofalse): activate an ACL allowing access only from Cloudflare IPsNGINX_HTTPS_ONLY(boolean, defaults tofalse): tellnginxto auto-redirect non-SSL traffic to SSL site.
NOTE: if used with Cloudflare,
NGINX_HTTPS_ONLYwill cause an infinite redirect loop - keep it set tofalse, useNGINX_CLOUDFLARE_ACLinstead and add a Cloudflare Page Rule to "Always Use HTTPS" for your server (usedomain.name/*to match all URLs).
nginx Caching
When NGINX_CACHE_PREFIXES is set, nginx will cache requests for those URL prefixes to the running application (uwsgi-like or web workers) and reply on its own for NGINX_CACHE_TIME to the outside. This is meant to be used for compute-intensive operations like resizing images or providing large chunks of data that change infrequently (like a sitemap).
The behavior of the cache can be controlled with the following variables:
NGINX_CACHE_PREFIXES(string, comma separated list): set an array of/urlvalues that will be cached bynginxNGINX_CACHE_SIZE(integer, defaults to 1): set the maximum size of thenginxcache, in GBNGINX_CACHE_TIME(integer, defaults to 3600): set the amount of time (in seconds) that valid backend replies (200 304) will be cached.NGINX_CACHE_REDIRECTS(integer, defaults to 3600): set the amount of time (in seconds) that backend redirects (301 307) will be cached.NGINX_CACHE_ANY(integer, defaults to 3600): set the amount of time (in seconds) that any other replies (other than errors) will be cached.NGINX_CACHE_CONTROL(integer, defaults to 3600): set the amount of time (in seconds) for cache control headers (Cache-Control "public, max-age=3600")NGINX_CACHE_EXPIRY(integer, defaults to 86400): set the amount of time (in seconds) that cache entries will be kept on disk.NGINX_CACHE_PATH(string, detaults to~piku/.piku/<appname>/cache): location for thenginxcache data.
NOTE:
NGINX_CACHE_PATHwill be completely managed bynginxand cannot be removed by Piku when the application is destroyed. This is becausenginxsets the ownership for the cache to be exclusive to itself, and thepikuuser cannot remove that file tree. So you will either need to clean it up manually after destroying the app or store it in a temporary filesystem (or set thepikuuser to the same UID aswww-data, which is not recommended).
Right now, there is no provision for cache revalidation (i.e., nginx asking your backend if the cache entries are still valid), since that requires active application logic that varies depending on the runtime--nginx will only ask your backend for new content when NGINX_CACHE_TIME elapses. If you require that kind of behavior, that is still possible via NGINX_INCLUDE_FILE.
Also, keep in mind that using nginx caching with a static website worker will not work (and there's no point to it either).
nginx Overrides
NGINX_INCLUDE_FILE: a file in the app's dir to include in nginx configserversection - useful for including customnginxdirectives.NGINX_ALLOW_GIT_FOLDERS: (boolean) allow access to.gitfolders (default: false, blocked)NGINX_CATCH_ALL(string, defaults to ""): specifies a filename to serve to all requests regardless of path (useful when using client-side routing)
Acme Settings
ACME_ROOT_CA: set the certificate authority that Acme should use to generate public ssl certificates (string, default:letsencrypt.org)