Skip to content

Instantly share code, notes, and snippets.

@saml
Last active December 12, 2015 00:28
Show Gist options
  • Save saml/4683701 to your computer and use it in GitHub Desktop.
Save saml/4683701 to your computer and use it in GitHub Desktop.
nginx proxy cache
#!/bin/bash
CACHE_PATH="/var/www/cache"
if (( $# < 1 ))
then
sudo rm -rf "$CACHE_PATH"/*
else
curl -H "X-Purge: 1" -g -s -v "$1"
fi
proxy_cache_path /var/www/cache levels=2:2 keys_zone=default:3000m inactive=24h;
proxy_temp_path /var/www/tmp;
server {
server_name example.com;
proxy_set_header Referer $proxy_host;
proxy_cache default;
proxy_cache_valid 200 24h;
location / {
add_header X-Cache-Status $upstream_cache_status;
proxy_pass http://app.server:4502/;
proxy_cache_bypass $http_x_purge_header; # curl -H "X-Purge: 1" to re-cache.
proxy_ignore_headers Set-Cookie;
proxy_hide_header Set-Cookie;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment