Skip to content

Instantly share code, notes, and snippets.

@marcparadise
Created February 5, 2015 19:07
Show Gist options
  • Save marcparadise/11e1bb98c56873fe9b2c to your computer and use it in GitHub Desktop.
Save marcparadise/11e1bb98c56873fe9b2c to your computer and use it in GitHub Desktop.
proxy_cache_path /tmp/cache keys_zone=cookbooks:10m;
##
server {
listen 8001;
allow 127.0.0.1;
deny all;
location / {
echo "hello there young padawan! Welcome to $uri. " ;
echo "This request would $http_x_cache_status been cached. " ;
echo "Verify request params preserved: $args ";
}
}
upstream bookshelf {
server localhost:8001 ;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# Make site accessible from http://localhost/
server_name localhost;
location ~ ^/bookshelf/?(.*)$ {
set $destination "uncached";
if ($request_method = "GET") {
set $destination "cached" ;
}
rewrite ^(.*)$ /$destination-bookshelf/$1 last;
}
location ~ ^/cached-bookshelf/?(.*)$ {
internal;
proxy_cache cookbooks;
more_clear_headers 'Cache-Control';
proxy_set_header X-Proxy-Cache $upstream_cache_status;
proxy_set_header X-Cache-Status "have";
proxy_pass http://bookshelf/$1?$args;
}
location ~ ^/uncached-bookshelf/?(.*)$ {
internal;
proxy_set_header X-Cache-Status "have not";
proxy_pass http://bookshelf/$1?$args;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment