【发布时间】:2014-10-27 15:59:37
【问题描述】:
我有以下 nginx 配置:
upstream backend {
server localhost:8080;
}
upstream memcached_server {
server 127.0.0.1:11211;
}
server {
listen 3000;
server_name localhost;
location /picture {
set $memc_cmd get;
set $memc_key $arg_login;
memc_pass memcached_server;
error_page 404 = @cache_miss;
}
location @cache_miss {
proxy_pass http://backend;
}
location /image {
proxy_pass http://myimageservice;
}
当我向localhost:3000/picture?login=john 发送请求时,它会尝试使用键“john”在 memcached 中查找内容。当 memcached 中不存在内容时,它会将请求代理传递到后端服务器 (localhost:8080),该服务器将“X-Accel-Redirect”设置为 John 图像的路径。路径以 '/image' 开头,因此 nginx 从 myimageservice 获取数据并将其返回给客户端。
问题是我想缓存'myimageservice'返回的响应,所以下次调用localhost:3000/picture?login=john时,没有请求发送到后端服务器(localhost:8080),响应立即从内存缓存。有可能吗?
【问题讨论】: