mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-05-09 23:05:43 +02:00
Solved proxy cache bugs
This commit is contained in:
parent
d5f194b2c0
commit
1d52fcec75
@ -14,6 +14,8 @@ nginx:
|
|||||||
html: "/var/www/public_html/" # Path where the static homepage files are stored
|
html: "/var/www/public_html/" # Path where the static homepage files are stored
|
||||||
files: "/var/www/public_files/" # Path where the web accessable files are stored
|
files: "/var/www/public_files/" # Path where the web accessable files are stored
|
||||||
global: "/var/www/global/" # Directory containing files which will be globaly accessable
|
global: "/var/www/global/" # Directory containing files which will be globaly accessable
|
||||||
cache: "/tmp/nginx_cache/" # Directory which nginx uses to cache data
|
cache:
|
||||||
|
general: "/tmp/cache_nginx_general/" # Directory which nginx uses to cache general data
|
||||||
|
image: "/tmp/cache_nginx_image/" # Directory which nginx uses to cache images
|
||||||
user: "http" # Default nginx user in ArchLinux
|
user: "http" # Default nginx user in ArchLinux
|
||||||
iframe: true # Allows applications to be loaded in iframe
|
iframe: true # Allows applications to be loaded in iframe
|
@ -1,23 +0,0 @@
|
|||||||
- name: Remove (Cleanup) NGINX cache directory contents
|
|
||||||
become: true
|
|
||||||
file:
|
|
||||||
path: "{{ nginx.directories.cache }}"
|
|
||||||
state: absent
|
|
||||||
when:
|
|
||||||
- mode_cleanup | bool
|
|
||||||
- run_once_nginx_reverse_proxy is not defined
|
|
||||||
|
|
||||||
- name: Ensure NGINX cache directory exists
|
|
||||||
become: true
|
|
||||||
file:
|
|
||||||
path: "{{ nginx.directories.cache }}"
|
|
||||||
state: directory
|
|
||||||
owner: http
|
|
||||||
group: http
|
|
||||||
mode: '0755'
|
|
||||||
when: run_once_nginx_reverse_proxy is not defined
|
|
||||||
|
|
||||||
- name: run the nginx_reverse_proxy tasks once
|
|
||||||
set_fact:
|
|
||||||
run_once_nginx_reverse_proxy: true
|
|
||||||
when: run_once_nginx_reverse_proxy is not defined
|
|
@ -1,16 +1,10 @@
|
|||||||
proxy_cache_path {{ nginx.directories.cache }} levels=1:2 keys_zone=imgcache:10m inactive=60m use_temp_path=off;
|
|
||||||
|
|
||||||
{%- if location is defined %}
|
|
||||||
location ~* ^{{ location }}.*\.(jpg|jpeg|png|gif|webp|ico|svg)$ {
|
|
||||||
{%- else %}
|
|
||||||
location ~* \.(jpg|jpeg|png|gif|webp|ico|svg)$ {
|
location ~* \.(jpg|jpeg|png|gif|webp|ico|svg)$ {
|
||||||
{%- endif %}
|
|
||||||
# Cache in browser
|
# Cache in browser
|
||||||
expires 30d;
|
expires 30d;
|
||||||
add_header Cache-Control "public, max-age=2592000, immutable";
|
add_header Cache-Control "public, max-age=2592000, immutable";
|
||||||
|
|
||||||
# Cache on reverse proxy side
|
# Cache on reverse proxy side
|
||||||
proxy_pass http://127.0.0.1:{{http_port}}{{location | default("/")}};
|
proxy_pass http://127.0.0.1:{{http_port}};
|
||||||
proxy_cache imgcache;
|
proxy_cache imgcache;
|
||||||
proxy_cache_valid 200 302 60m;
|
proxy_cache_valid 200 302 60m;
|
||||||
proxy_cache_valid 404 1m;
|
proxy_cache_valid 404 1m;
|
||||||
|
30
roles/nginx/tasks/cache_directories.yml
Normal file
30
roles/nginx/tasks/cache_directories.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
- name: Cleanup all NGINX cache directories
|
||||||
|
become: true
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ item.value }}"
|
||||||
|
state: absent
|
||||||
|
when:
|
||||||
|
- mode_cleanup | bool
|
||||||
|
- run_once_nginx_reverse_proxy is not defined
|
||||||
|
loop: "{{ nginx.directories.cache | dict2items }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.key }}"
|
||||||
|
|
||||||
|
- name: Ensure all NGINX cache directories exist
|
||||||
|
become: true
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ item.value }}"
|
||||||
|
state: directory
|
||||||
|
owner: "{{ nginx.user }}"
|
||||||
|
group: "{{ nginx.user }}"
|
||||||
|
mode: '0700'
|
||||||
|
|
||||||
|
when: run_once_nginx_reverse_proxy is not defined
|
||||||
|
loop: "{{ nginx.directories.cache | dict2items }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.key }}"
|
||||||
|
|
||||||
|
- name: run the nginx_reverse_proxy tasks once
|
||||||
|
set_fact:
|
||||||
|
run_once_nginx_reverse_proxy: true
|
||||||
|
when: run_once_nginx_reverse_proxy is not defined
|
@ -42,6 +42,9 @@
|
|||||||
{{ nginx.directories.data.values() | list }}
|
{{ nginx.directories.data.values() | list }}
|
||||||
when: run_once_nginx is not defined
|
when: run_once_nginx is not defined
|
||||||
|
|
||||||
|
- name: "Include tasks to create cache directories"
|
||||||
|
include_tasks: cache_directories.yml
|
||||||
|
|
||||||
- name: create nginx config file
|
- name: create nginx config file
|
||||||
template:
|
template:
|
||||||
src: nginx.conf.j2
|
src: nginx.conf.j2
|
||||||
|
@ -12,7 +12,14 @@ http
|
|||||||
default_type text/html;
|
default_type text/html;
|
||||||
|
|
||||||
{# caching #}
|
{# caching #}
|
||||||
proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:20m max_size=20g inactive=14d use_temp_path=off;
|
proxy_cache_path {{ nginx.directories.cache.general }} levels=1:2 keys_zone=cache:20m max_size=20g inactive=14d use_temp_path=off;
|
||||||
|
proxy_cache_path {{ nginx.directories.cache.image }} levels=1:2 keys_zone=imgcache:10m inactive=60m use_temp_path=off;
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------
|
||||||
|
# Tweak the hash table used to store your server_name entries:
|
||||||
|
server_names_hash_bucket_size 64; # size of each bucket for server_name lookups (in bytes)
|
||||||
|
server_names_hash_max_size 512; # maximum total buckets for the server_name hash table
|
||||||
|
# --------------------------------------------------------------------------------
|
||||||
|
|
||||||
{# logging and debugging #}
|
{# logging and debugging #}
|
||||||
{% if enable_debug | bool %}
|
{% if enable_debug | bool %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user