Thursday, 27 June 2019

NGINX - Tackling Tricky deployment config aspects- Caching

Continuing on deployment tricks on Angular application

Lets have a look on caching strategy for configuration in Angular

The file that become matter of importance is default.conf

If you application context path is : myapplication

Add below as first line in default.conf 

proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=MY_APPLICATION_CACHE:10m inactive=24h use_temp_path=off;

Add caching reference in block where application is looking for configuration:

In this case: config of application is stored under assets folder

 location /myapplication/assets/env/ {
        proxy_pass http://config-service:9090/ENV/SPRING_CONFIG_PROFILE/master/;
        proxy_buffering on;
        proxy_ignore_headers Cache-Control Set-Cookie;
        proxy_cache MY_APPLICATION_CACHE;
        proxy_cache_valid 200 1d;
        proxy_cache_lock on;
        proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504 http_403 http_404;

Thank you!

Satender Kumar Mall
Twitter: @satenderiiit