Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


CDN Cache Status
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

CDN Cache Status

Luke007Luke007 Member

So I tried building my own 3 continent CDN but not able figure out the cache status header.
How can I add CDN-Cache status header to this config? -http://pastebin.com/bbi9Z5p4

I tried adding the below header but it is not working

X-CDN-Cache-Status $upstream_cache_status;

Comments

  • BunnySpeedBunnySpeed Member, Host Rep
    edited March 2017

    I forgot why exactly, but we do this:

        if ($http_cache_status = 'HIT') {
            more_set_headers "CDN-Cache: HIT";
        }
        if ($http_cache_status != 'HIT') {
            more_set_headers "CDN-Cache: $upstream_cache_status";
        }
    
    Thanked by 1Luke007
  • WSSWSS Member
    edited March 2017

    @BunnySpeed said:

    I forgot why exactly, but we do this:

    >

         if ($http_cache_status = 'HIT') {
             more_set_headers "CDN-Cache: HIT";
         }
         if ($http_cache_status != 'HIT') {
             more_set_headers "CDN-Cache: $upstream_cache_status";
         }

    I know you don't do that, because it's wrong. You'd likely do a test, rather than an assign. :)

    I like abusing ternary (when it works, it works!).

    more_set_headers (($http_cache_status == 'HIT') ? 'CDN-Cache: HIT' : 'CDN-Cache: '.$upstream_cache_status);

    Thanked by 1yomero
  • BunnySpeedBunnySpeed Member, Host Rep
    edited March 2017

    It's nginx. Pretty sure that's working.

  • didtavdidtav Member
    edited March 2017

    I use mirror servers, it will definitely 1000% hit, and will stay forever in edge servers even it never ever accessed

    No need of cache status

  • ZiriusPHZiriusPH Member
    edited March 2017

    @BunnySpeed said:
    It's nginx. Pretty sure that's working.

    He is referring to this:

    if ($http_cache_status = 'HIT') {

    should be

    if ($http_cache_status == 'HIT') {

    Thanked by 2WSS yomero
  • nfnnfn Veteran

    $upstream_cache_status: keeps the status of accessing a response cache (0.8.3). The status can be either “MISS”, “BYPASS”, “EXPIRED”, “STALE”, “UPDATING”, “REVALIDATED”, or “HIT”.

    You just need to add more_set_headers CDN-Cache $upstream_cache_status;

  • BunnySpeedBunnySpeed Member, Host Rep
    edited March 2017

    @ZiriusPH said:

    @BunnySpeed said:
    It's nginx. Pretty sure that's working.

    He is referring to this:

    if ($http_cache_status = 'HIT') {

    should be

    if ($http_cache_status == 'HIT') {

    The code that you posted does not work on nginx.
    I posted a working solution, you're correcting me with a broken one lol

    Try it. Nginx throws: unexpected "==" in condition in /etc/....

    EDIT: I also remembered why we use more_set_headers. You should probably use the normal add_header, I just used this because it needed to override the already existing header.

    Thanked by 1ZiriusPH
  • WSSWSS Member

    @BunnySpeed said:
    The code that you posted does not work on nginx.
    I posted a working solution, you're correcting me with a broken one lol

    It's because nginx pragmatically does it wrong. :)

    = generally means "assign this to variable" not "does this equal that"?

  • YuraYura Member

    @WSS said:

    @BunnySpeed said:
    The code that you posted does not work on nginx.
    I posted a working solution, you're correcting me with a broken one lol

    It's because nginx pragmatically does it wrong. :)

    = generally means "assign this to variable" not "does this equal that"?

    Or pattern matching ;)

    Ok ok, I will show myself out now. Bye, bye, C.

  • WSSWSS Member

    @Yura said:

    @WSS said:

    @BunnySpeed said:
    The code that you posted does not work on nginx.
    I posted a working solution, you're correcting me with a broken one lol

    It's because nginx pragmatically does it wrong. :)

    = generally means "assign this to variable" not "does this equal that"?

    Or pattern matching ;)

    Ok ok, I will show myself out now. Bye, bye, C.

    I'm hereby forcing you to use nothing but m4 and [BrainF$#%*] (https://en.wikipedia.org/wiki/Brainfuck) for the rest of your career. Smartass.

    Thanked by 1Yura
  • @BunnySpeed @didtav The CDN is passing every request to the origin server even though static resources are cached in the CDN. What wrong am I doing here?
    Here is the nginx config - http://pastebin.com/bbi9Z5p4

  • BunnySpeedBunnySpeed Member, Host Rep

    First, if you're making a CDN, you're probably looking to use proxy_cache instead of proxy_store.

    Second, you might want to try to follow a tutorial explaining how to do this from scratch. You could try following something like this:
    https://mattgadient.com/2014/01/28/making-your-own-cdn-edge-cache-on-the-cheap/

    I haven't actually read the whole article, but it seems to explain things in detail.

    Thanked by 1Luke007
  • @Luke007 said:
    @BunnySpeed @didtav The CDN is passing every request to the origin server even though static resources are cached in the CDN. What wrong am I doing here?
    Here is the nginx config - http://pastebin.com/bbi9Z5p4

    we are on a different pathway, bro.

    I'm using a really really simple method to get my cdn work, the only software I installed on the edge server is nginx optimized to serve static content and then use rsync to automatically mirror my main server to all edge servers.

    multiple servers > rsync > GeoDNS > done

    I don't use nginx to proxy any request

Sign In or Register to comment.