diff --git a/README.md b/README.md index ffea823..e549665 100644 --- a/README.md +++ b/README.md @@ -29,4 +29,13 @@ This role supports uninstalling cleanly. If you run the role with `php_uninstall resources created by the role will be removed. This however, excludes system packages because we want to avoid removing packages that another role might need. +## FastCGI Cache + +You can enable FastCGI Cache by setting `php_fastcgi_cache_enabled` to `true`. +If you want to clear the cache, you need to call from the same machine this +corresponding URL : `http://[[php_base_name]].purge.cache.fastcgi.nginx.local/` + +More information about caching features can be found in `defaults/main.yml`. + + [ansible-nginx]: https://github.com/savoirfairelinux/ansible-nginx diff --git a/defaults/main.yml b/defaults/main.yml index 5035f6c..977cddf 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -77,3 +77,30 @@ php_http_basic_auth_accounts: [] # password: whatever42 # - username: alice # password: rocknroll42 + +# Enable FastCGI cache +php_fastcgi_cache_enabled: false + +# set fastcgi cache storage path +php_fastcgi_cache_storage_path: "/dev/shm/nginx_fastcgi_cache_{{ php_base_name }}" + +# maximum size of cache in Mb +php_fastcgi_cache_max_size_mb: 256 + +# minutes before cached page expiration +php_fastcgi_cache_expiration_minutes: 10080 + +# the request uris regexes to not cache +php_fastcgi_cache_ignored_uri_regex_matches: [] + +# if you want to not cache post requests +php_fastcgi_cache_ignore_post_requests: true + +# where you want to save the cache clear script +php_fastcgi_cache_purge_script_path: "" + +# if nginx requests per second limit must be enabled (outer static assets) +php_limitreq_enabled: false + +# the maximum requests per second per client IP address to throw HTTP error +php_limitreq_per_second: 15 diff --git a/tasks/nginx.yml b/tasks/nginx.yml index bde6df9..8f6a665 100644 --- a/tasks/nginx.yml +++ b/tasks/nginx.yml @@ -20,3 +20,24 @@ - name: Create config for site template: "src=nginx.conf dest=/etc/nginx/sites-enabled/{{ php_base_name }}.conf" notify: nginx restart + +# Older versions of nginx shipped with package manager does not support +# fastcgi_cache_purge, and fastcgi refuses to give rights over cache files to +# particular users, and LXDock sets nosuid so we required to workaround this +# by creating a simple script owned by www-data that delete the cache by itself. +# For this version, the whole cache will be cleared because it do the +# job for what we need. May be required to upgrade this method in the future. +- name: Ensure a script that www-data can execute to clear FastCGI Cache + template: + src: cache-clear-script.conf + dest: "{{ php_fastcgi_cache_purge_script_path }}" + mode: 0050 + owner: root + group: www-data + when: php_fastcgi_cache_enabled + +- name: Ensure that the FastCGI Cache clear URL is reachable + lineinfile: + path: /etc/hosts + line: "127.0.0.1 {{ php_base_name }}.purge.cache.fastcgi.nginx.local" + when: php_fastcgi_cache_enabled diff --git a/templates/cache-clear-script.conf b/templates/cache-clear-script.conf new file mode 100644 index 0000000..0a703dd --- /dev/null +++ b/templates/cache-clear-script.conf @@ -0,0 +1,2 @@ +