Nginx反向代理:Post_action如果代理caching命中 – Possbile?

我们最近发现了有关nginxpost_action

我们想知道是否有一种方法来使用这个指令,如果一个代理caching命中?

我们希望的stream程如下:

 1) User request comes in 2) If cache HIT goto A / If cache MISS goto B A) 1) Serve Cached Result A) 2) post_action to another url on the backend B) 1) Server request from backend B) 2) Store result from backend 

任何想法,如果这可能通过post_action或任何其他方法?

这背后的推理如下:

我们本质上是喜欢修改用户会话(php,但是相同的概念可以适用于大多数服务器端语言),同时显示caching的内容。 这将大大增加我们处理caching的请求的数量,因为这些请求只写入会话,而不是读取它们。

谢谢!

如果你还没有解决这个问题,这里是通过你的要求的示例configuration:

 服务器{
    听80;
     server_name img1.example;
     root / var / www / images;
    位置/ {//用户请求进来
         try_files $ uri @proxy;  //如果cachingHIT goto A(show)/如果cachingMISS goto B(@proxy),则caching服务器的结果
         post_action /url.php;  // post_action到后端的另一个url
     }

    位置@proxy {
         proxy_pass http://static.exmaple;  //来自后端的服务器请求
         proxy_store / var / www / images $ uri;  //从后端存储结果(caching)
     }
 }

我没有testing过,但你可以用try_files来实现。

 location / { post_action /update-session; try_files $uri @cachemiss; } location @cachemiss { #pass to relevant backend post_action off; #this may or may not be needed... is post_action cleared when we change location blocks? } location /update-session { #pass to session update script } 

我们都做的另一个假设是post_action收到所有相同的HTTP头作为父请求。