Skip to content

Commit cb014cd

Browse files
pritpal-sabharwalalessfg
authored andcommitted
Added proxy_cache_valid support (#192)
1 parent baafb8d commit cb014cd

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,11 @@ nginx_http_template:
538538
verify_depth: 1
539539
session_reuse: true
540540
proxy_cache: frontend_proxy_cache
541+
proxy_cache_valid:
542+
- code: 200
543+
time: 10m
544+
- code: 301
545+
time: 1m
541546
proxy_temp_path:
542547
path: /var/cache/nginx/proxy/backend/temp
543548
proxy_cache_lock: false

defaults/main.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ nginx_http_template:
283283
use_temp_path: true
284284
proxy_temp_path:
285285
path: /var/cache/nginx/proxy/temp
286+
proxy_cache_valid:
287+
- code: 200
288+
time: 10m
289+
- code: 301
290+
time: 1m
286291
proxy_cache_lock: true
287292
proxy_cache_min_uses: 5
288293
proxy_cache_revalidate: true
@@ -350,7 +355,12 @@ nginx_http_template:
350355
verify: false
351356
verify_depth: 1
352357
session_reuse: true
353-
proxy_cache: frontend_proxy_cache
358+
proxy_cache: backend_proxy_cache
359+
proxy_cache_valid:
360+
- code: 200
361+
time: 10m
362+
- code: 301
363+
time: 1m
354364
proxy_temp_path:
355365
path: /var/cache/nginx/proxy/backend/temp
356366
proxy_cache_lock: false

molecule/template/playbook.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@
102102
always: false
103103
proxy_pass: http://frontend_servers/
104104
proxy_cache: frontend_proxy_cache
105+
proxy_cache_valid:
106+
- code: 200
107+
time: 10m
108+
- code: 301
109+
time: 1m
105110
proxy_temp_path:
106111
path: /var/cache/nginx/proxy/frontend/temp
107112
proxy_cache_lock: false
@@ -133,6 +138,8 @@
133138
location: /backend
134139
proxy_pass: http://backend_servers/
135140
proxy_cache: backend_proxy_cache
141+
proxy_cache_valid:
142+
- time: 10m
136143
proxy_temp_path:
137144
path: /var/cache/nginx/proxy/backend/temp
138145
proxy_cache_lock: true

templates/http/default.conf.j2

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ upstream {{ item.value.upstreams[upstream].name }} {
2626
{% if item.value.reverse_proxy.proxy_cache_path is defined and item.value.reverse_proxy.proxy_cache_path %}
2727
{% for proxy_cache_path in item.value.reverse_proxy.proxy_cache_path %}
2828
proxy_cache_path {{ proxy_cache_path.path }} keys_zone={{ proxy_cache_path.keys_zone.name }}:{{ proxy_cache_path.keys_zone.size }}
29-
levels={{ proxy_cache_path.levels }} max_size={{ proxy_cache_path.max_size }}
30-
inactive={{ proxy_cache_path.inactive }} use_temp_path={{ proxy_cache_path.use_temp_path | ternary("on", "off") }};
29+
levels={{ proxy_cache_path.levels }} max_size={{ proxy_cache_path.max_size }}
30+
inactive={{ proxy_cache_path.inactive }} use_temp_path={{ proxy_cache_path.use_temp_path | ternary("on", "off") }};
3131
{% endfor %}
3232
{% if item.value.reverse_proxy.proxy_cache_background_update is defined and item.value.reverse_proxy.proxy_cache_background_update%}
3333
proxy_cache_background_update {{ item.value.reverse_proxy.proxy_cache_background_update | ternary("on", "off") }};
@@ -50,6 +50,15 @@ proxy_ignore_headers {{ item.value.reverse_proxy.proxy_ignore_headers | join(" "
5050
{% if item.value.reverse_proxy.proxy_temp_path is defined and item.value.reverse_proxy.proxy_temp_path.path %}
5151
proxy_temp_path {{ item.value.reverse_proxy.proxy_temp_path.path }} {{ item.value.reverse_proxy.proxy_temp_path.level_1 | default("") }} {{ item.value.reverse_proxy.proxy_temp_path.level_2 | default("") }} {{ item.value.reverse_proxy.proxy_temp_path.level_3 | default("") }};
5252
{% endif %}
53+
{% if item.value.reverse_proxy.proxy_cache_valid is defined %}
54+
{% for proxy_cache_valid in item.value.reverse_proxy.proxy_cache_valid %}
55+
{% if proxy_cache_valid.code is defined %}
56+
proxy_cache_valid {{ proxy_cache_valid.code }} {{ proxy_cache_valid.time | default("10m") }};
57+
{% elif proxy_cache_valid.time is defined and proxy_cache_valid.code is not defined %}
58+
proxy_cache_valid {{ proxy_cache_valid.time }};
59+
{% endif %}
60+
{% endfor %}
61+
{% endif %}
5362
{% endif %}
5463
{% endif %}
5564
{% if item.value.auth_request_http is defined %}
@@ -282,6 +291,15 @@ server {
282291
{% if item.value.reverse_proxy.locations[location].proxy_cache is defined %}
283292
proxy_cache {{ item.value.reverse_proxy.locations[location].proxy_cache }};
284293
{% endif %}
294+
{% if item.value.reverse_proxy.locations[location].proxy_cache_valid is defined %}
295+
{% for proxy_cache_valid in item.value.reverse_proxy.locations[location].proxy_cache_valid %}
296+
{% if proxy_cache_valid.code is defined %}
297+
proxy_cache_valid {{ proxy_cache_valid.code }} {{ proxy_cache_valid.time | default("10m") }};
298+
{% elif proxy_cache_valid.time is defined and proxy_cache_valid.code is not defined %}
299+
proxy_cache_valid {{ proxy_cache_valid.time }};
300+
{% endif %}
301+
{% endfor %}
302+
{% endif %}
285303
{% if item.value.reverse_proxy.locations[location].proxy_cache_background_update is defined %}
286304
proxy_cache_background_update {{ item.value.reverse_proxy.locations[location].proxy_cache_background_update | ternary("on", "off") }};
287305
{% endif %}

0 commit comments

Comments
 (0)