├── commands ├── nginx-pre-reload ├── plugin.toml └── readme.md /commands: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x 3 | 4 | PLUGIN_BASE_PATH="$PLUGIN_PATH" 5 | if [[ -n $DOKKU_API_VERSION ]]; then 6 | PLUGIN_BASE_PATH="$PLUGIN_ENABLED_PATH" 7 | fi 8 | source "$PLUGIN_BASE_PATH/common/functions" 9 | 10 | case "$1" in 11 | nginx:cache:enable) 12 | verify_app_name "$2" 13 | APP="$2" 14 | 15 | touch $DOKKU_ROOT/$APP/NGINX_PROXY_CACHE 16 | echo "Enabled nginx proxy cache for $APP" 17 | 18 | dokku_log_info1 "Restarting app $APP" 19 | dokku ps:restart "$APP" 20 | ;; 21 | 22 | nginx:cache:disable) 23 | verify_app_name "$2" 24 | APP="$2" 25 | 26 | if [[ ! -e $DOKKU_ROOT/$APP/NGINX_PROXY_CACHE ]]; then 27 | echo "Nginx proxy cache is not enabled for $APP" 28 | else 29 | rm -rf $DOKKU_ROOT/$APP/NGINX_PROXY_CACHE 30 | echo "Disabled nginx proxy cache for $APP" 31 | 32 | dokku_log_info1 "Restarting app $APP" 33 | dokku ps:restart "$APP" 34 | fi 35 | ;; 36 | 37 | help | nginx:cache:help) 38 | help_content_func () { 39 | declare desc="return help_content string" 40 | cat<, Enable nginx proxy cache for 42 | nginx:cache:disable , Disable nginx proxy cache for 43 | help_content 44 | } 45 | 46 | if [[ $1 = "nginx:cache:help" ]] ; then 47 | echo -e 'Usage: dokku nginx:cache:[enable|disable] ' 48 | echo '' 49 | echo 'Toggle nginx proxy cache.' 50 | echo '' 51 | echo 'Commands:' 52 | help_content_func | sort | column -c2 -t -s, 53 | else 54 | help_content_func 55 | fi 56 | ;; 57 | 58 | *) 59 | exit $DOKKU_NOT_IMPLEMENTED_EXIT 60 | ;; 61 | 62 | esac 63 | -------------------------------------------------------------------------------- /nginx-pre-reload: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x 3 | 4 | APP=$1 5 | 6 | # Exit if nginx-cache is not enabled for this app 7 | if [[ ! -e $DOKKU_ROOT/$APP/NGINX_PROXY_CACHE ]]; then 8 | exit 0 9 | fi 10 | 11 | function add_setting_upstream { 12 | sed -i -r "s/upstream.*$/\0\n $1/g" $DOKKU_ROOT/$APP/nginx.conf 13 | } 14 | 15 | function add_setting_location { 16 | sed -i -r "s/proxy_pass.*$/\0\n $1/g" $DOKKU_ROOT/$APP/nginx.conf 17 | } 18 | 19 | add_setting_upstream "proxy_cache_key \$scheme\$request_method\$host\$request_uri;" 20 | add_setting_upstream "proxy_cache_path \\/tmp\\/nginx levels:1-2 keys_zone=dokku:10m inactive=60m use_temp_path=off;" 21 | 22 | add_setting_location "proxy_cache dokku;" 23 | -------------------------------------------------------------------------------- /plugin.toml: -------------------------------------------------------------------------------- 1 | [plugin] 2 | description = "dokku nginx cache plugin" 3 | version = "0.2.0" 4 | [plugin.config] 5 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # dokku-nginx-cache 2 | 3 | Wire in nginx's proxy cache directives. 4 | 5 | ### Install 6 | 7 | ``` 8 | dokku plugin:install https://github.com/Aluxian/dokku-nginx-cache.git nginx-cache 9 | ``` 10 | 11 | ### Quick start 12 | 13 | Enable nginx request caching 14 | 15 | ``` 16 | $ dokku nginx:cache:enable myapp 17 | ``` 18 | 19 | Disable nginx request caching 20 | 21 | ``` 22 | $ dokku nginx:cache:disable myapp 23 | ``` 24 | 25 | ### Configuration 26 | 27 | Currently there are no configuration options. However, Nginx does obey a number of caching- and `X-Accel-*`-related headers. 28 | 29 | Snippet from [nginx docs][]: 30 | 31 | - `X-Accel-Expires`, `Expires`, `Cache-Control`, `Set-Cookie`, and `Vary` set the parameters of response [caching][]; 32 | - `X-Accel-Redirect` performs an [internal redirect][] to the specified URI; 33 | - `X-Accel-Limit-Rate` sets the [rate limit][] for transmission of a response to a client; 34 | - `X-Accel-Buffering` enables or disables [buffering][] of a response; 35 | - `X-Accel-Charset` sets the desired [charset][] of a response. 36 | 37 | [nginx docs]: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers 38 | [caching]: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_valid 39 | [internal redirect]: http://nginx.org/en/docs/http/ngx_http_core_module.html#internal 40 | [rate limit]: http://nginx.org/en/docs/http/ngx_http_core_module.html#limit_rate 41 | [buffering]: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering 42 | [charset]: http://nginx.org/en/docs/http/ngx_http_charset_module.html#charset 43 | --------------------------------------------------------------------------------