proxy_cache not serving file from edge server !!

shahzaib shahzaib shahzaib.cb at
Tue Jul 1 11:57:21 UTC 2014

We've an origin and edge server with nginx-1.6 . Origin web-server(Located
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 and
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 in
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 file
locally and if file is not in proxy_cache, it'll pass back the request to
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 edge
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 serving
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 server,
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_add_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 inactive=1d

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list