Created
August 3, 2016 16:50
-
-
Save kmjones1979/83bf8175449464733e94fbadcfc17518 to your computer and use it in GitHub Desktop.
Dynamic Cache based on header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user nginx; | |
worker_processes auto; | |
error_log /var/log/nginx/error.log notice; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
keepalive_timeout 65; | |
#gzip on; | |
proxy_cache_path /path/to/cache1 levels=1:2 keys_zone=cache1:10m max_size=1g inactive=60m | |
use_temp_path=off; | |
proxy_cache_path /path/to/cache2 levels=1:2 keys_zone=cache2:10m max_size=1g inactive=60m | |
use_temp_path=off; | |
proxy_cache_path /path/to/cache3 levels=1:2 keys_zone=default_cache:10m max_size=1g inactive=60m | |
use_temp_path=off; | |
map $http_x_client $dynamic_cache { | |
~*service1 cache1; | |
~*service2 cache2; | |
default default_cache; | |
} | |
upstream backend { | |
server 127.0.0.1:8000; | |
} | |
server { | |
listen 80; | |
location /instrument { | |
proxy_cache_valid any 30m; | |
proxy_cache $dynamic_cache; | |
proxy_pass http://backend; | |
} | |
} | |
server { | |
listen 8000; | |
location / { | |
return 200 "200 OK | |
upstream_cache_status: $upstream_cache_status | |
http_x_client: $http_x_client | |
dynamic_cache: $dynamic_cache\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment