yj-t
5/19/2016 - 11:35 PM

Web Rules (nginx conf) in MODX Cloud for CDN, proxy caching assets, and statcache

Web Rules (nginx conf) in MODX Cloud for CDN, proxy caching assets, and statcache

# statcache bits
set $cache_prefix 'statcache';
if ($http_user_agent = 'MODX RegenCache') {
    set $cache_prefix 'no cache';
}
# CORS for CDN pull zone and expires directives
location ~* \.(?:ico|css|js|jpe?g|png|gif|svg|pdf|mov|mp4|mp3|woff|woff2|ttf|ttc|otf|eot|font.css)$ {
    expires 7d;
    add_header Access-Control-Allow-Origin "*";   
    add_header Pragma public;
    add_header Cache-Control "public";
    gzip_vary on;
}
# modified modx rewrite for statcache
location / {
    try_files /$cache_prefix$uri~index.html /$cache_prefix$uri $uri $uri/ @modx-rewrite;
}