Forum: NGINX proxy_cache not serving file from edge server!

13731c628e20ffd83b6114ff2c406272?d=identicon&s=25 shahzaib mushtaq (shahzaib12)
on 2014-07-01 13:58
(Received via mailing list)
We've an origin and edge server with nginx-1.6 . Origin
in U.S) is configured with nginx_geo_module and edge(Local ISP) is
configured with proxy_cache in order to cache files from origin server
serve from their lately. We're using following method for caching with
proxy_cache :-

1. client ( sends mp4 request to origin webserver and geo_module
origin checks, if the ip is then pass that client to the edge
server using proxy_pass.

2. Edge, checks if the file is in proxy_cache than it should serve the
locally and if file is not in proxy_cache, it'll pass back the request
origin server and client will be served from origin server as well as
requested file will also be cached in local server, so next time the
will not have to pass request again to origin server and serve the same
file via locally.

But, looks like our caching is not working as expected. Our ISP is
complaining that, whenever edge server serves the file, instead of
that file to local client ( it serves the file back to origin
server(U.S) and all outgoing bandwidth is going back to U.S instead of
local clients (Offcourse bandwidth not being saved).

So i want to ask, if the origin server is passing request to edge
the cached file must be served locally but the request going back to the
origin server even the cache status: HIT. Following are my configs :-


geo $TW {
  default 0; 1;


server {
        listen  80;
        location / {
            root   /var/www/html/files;
            index index.html index.htm index.php;


location ~ \.(mp4|jpg)$ {

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For
                proxy_set_header Host $http_host;
                if ($TW) {
                root /var/www/html/files;

                expires 7d;
        valid_referers none blocked *
*. * * * *;
                if ($invalid_referer) {
                    return   403;

 # pass the PHP scripts to FastCGI server listening on
        location ~ \.php$ {
            root /var/www/html/files;
           fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME
            include        fastcgi_params;

        location ~ /\.ht {
            deny  all;


#proxy_ignore_headers "Set-Cookie";
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=static:100m
                        loader_threshold=200 loader_files=500

server {

        listen       80;
        root /var/www/html/files;
        location ~ \.(mp4|jpeg|jpg)$ {
               root   /var/www/html/files;
                try_files $uri @getfrom_origin;


        location @getfrom_origin {
#       proxy_cache_valid 200 302   60m;
        proxy_cache_valid  15d;
        proxy_cache static;
        proxy_cache_min_uses 1;


Help will be highly appreciated.
13731c628e20ffd83b6114ff2c406272?d=identicon&s=25 shahzaib mushtaq (shahzaib12)
on 2014-07-01 14:08
(Received via mailing list)
Our caching method is :-

client ----> origin ---> edge.

On Tue, Jul 1, 2014 at 4:57 PM, shahzaib shahzaib
2974d09ac2541e892966b762aad84943?d=identicon&s=25 itpp2012 (Guest)
on 2014-07-01 14:49
(Received via mailing list)
shahzaib1232 Wrote:
> Our caching method is :-
> client ----> origin ---> edge.

This is not going to work as expected, you need client ----> edge --->

Where edge proxy-passes to origin when file is not in cache.

Posted at Nginx Forum:,251374,251384#msg-251384
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.