Git Product home page Git Product logo

Comments (8)

kapouer avatar kapouer commented on July 24, 2024

Your website varies the response using the request IP.
That setup doesn't go well with a cache in the proxy.
The right way to do this is to map the request IP to a request Header before srcache handles the request, and Vary the response upon that header.

  • Request:
    IP: a.b.c.d
    host: domain.com
    Accept: text/html
  • Geolocation nginx plugin (using e.g. ngx_http_geoip_module)
    IP: a.b.c.d
    host: domain.com
    Accept: text/html
    X-ClientCountry: France
  • Srcache:
    Here you should build the request key using X-ClientCountry header
  • Application:
    response.append('X-ClientCountry', 'Actual detected country')
    response.append('Vary', 'X-ClientCountry')
  • Srcache:
    Build store key using response X-ClientCountry header

from srcache-nginx-module.

kapouer avatar kapouer commented on July 24, 2024

I wrote Actual detected country because the Country detected by geoip might not be the one you actually choose in the application. For example you might map 'FR' and 'ES' to 'EU' in the application, so you have to tell the cache (as done above) to set its store key accordingly.

from srcache-nginx-module.

duylddev avatar duylddev commented on July 24, 2024

Thank you for replying, I understand that solution but I don't know how to build store key using response X-ClientCountry header.

Could you give more information?

from srcache-nginx-module.

duylddev avatar duylddev commented on July 24, 2024

It's great if you give me an example

from srcache-nginx-module.

kapouer avatar kapouer commented on July 24, 2024

From the documentation example (assuming you're using X-Client-Country header)

  more_set_headers 'X-Country-Code: $geoip_city_country_code3';
  set $fetchKey "$geoip_city_country_code3-$uri?$args";
  set $storeKey "$sent_http_x_client_country-$uri?$args";
  srcache_fetch GET /memc $fetchKey;
  srcache_store PUT /memc $storeKey;

Cool huh ?!?

from srcache-nginx-module.

duylddev avatar duylddev commented on July 24, 2024

set $key "example.com_page:https$http_cf_ipcountry$request_method$host$request_uri";

I'm using Cloudflare so that's my config and it's worked =))))

Thank you so much :D

from srcache-nginx-module.

kapouer avatar kapouer commented on July 24, 2024

Cool ! If you're using Cloudflare then yes, there is already a http header available, so indeed there is no need to set one up.
You might want to close this issue...

from srcache-nginx-module.

duylddev avatar duylddev commented on July 24, 2024

Oh, I forgot it
too much focus on coding =))

from srcache-nginx-module.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.