Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have recently found out about nginxes post_action.

We were wondering it there was a way to use this directive if a proxy cache hit is made?

The flow we were hoping on is as follows:

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

Any ideas if this is possible via post_action or any other method?

The reasoning behind this is as follows:

We would in essence like to modify the users session (php, but the same concept can apply to most server side languages) while displaying cached content. This would greatly increase the number of cache-able requests we process since these requests only WRITE to sessions, not read from them.

Thanks!

share|improve this question
add comment

2 Answers

If you didn't solve it yet here is example config that pass your requirements:

server {
    listen 80;
    server_name img1.example;
    root /var/www/images;
    location / { // Users request comes in
        try_files $uri @proxy; // If cache HIT goto A (show) / If cache MISS goto B (@proxy), server cached result
        post_action /url.php; // post_action to another url on the backend
    }

    location @proxy {
        proxy_pass http://static.exmaple; // Server request from backend
        proxy_store /var/www/images$uri; // Store result from backend (cache)
    }
}

share|improve this answer
    
It wasn't tested yet, but post_action shouldn't work when it HIT "@proxy", because post_action works in block that ends request - so when cache MISS, "@proxy" location will end and there is not post_action declaration. –  Misiek Sep 16 '12 at 20:13
    
i apologize to both who answered this question : as there will be some code involved, getting the session 'saver' setup, i have not yet had time to set this up. if the bounty expires, and i test both answers, i will re bounty this question and select whatever answer works. thank you VERY much for the help. –  anonymous-one Sep 16 '12 at 21:01
add comment

I haven't tested this but you may be able to achieve it with 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
}

Another assumption we are both making is that the post_action receives all the same HTTP headers as the parent request.

share|improve this answer
    
getting this all going will take a bit. will get back within 1-2 days regarding what i have found. thanks... yet again. –  anonymous-one Sep 12 '12 at 12:05
    
i apologize to both who answered this question : as there will be some code involved, getting the session 'saver' setup, i have not yet had time to set this up. if the bounty expires, and i test both answers, i will re bounty this question and select whatever answer works. thank you VERY much for the help. –  anonymous-one Sep 16 '12 at 21:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.