<div dir="ltr"><div><div>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 :-<br>
<br></div>1. client (1.1.1.1) sends mp4 request to origin webserver and geo_module in origin checks, if the ip is 1.1.1.1 then pass that client to the edge server using proxy_pass.<br><br> 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.<br>
<br></div><div>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 (1.1.1.1) 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).<br>
<br></div><div>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 :-<br>
<br></div><div>ORIGIN :-<br><br>geo $TW {<br>  default 0;<br>1.1.1.1 1;<br> <br>}<br><br><br><br>server {<br>        listen  80;<br>        server_name  <a href="http://origin.files.com">origin.files.com</a> <a href="http://origin.gear.net">origin.gear.net</a>  <a href="http://origin.gear.com">origin.gear.com</a>;<br>
        location / {<br>            root   /var/www/html/files;<br>            index index.html index.htm index.php;<br><br>}<br><br><br>location ~ \.(mp4|jpg)$ {<br><br>                proxy_set_header X-Real-IP $remote_addr;<br>
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>                proxy_set_header Host $http_host;<br>                if ($TW) {<br>                        proxy_pass <a href="http://tw002.edge.com:80">http://tw002.edge.com:80</a>;<br>
                }<br>                 mp4;<br>                root /var/www/html/files;<br><br><br>                expires 7d;<br>        valid_referers none blocked  <a href="http://video.pk">video.pk</a> *.<a href="http://video.pk">video.pk</a> <a href="http://blog.video.pk">blog.video.pk</a> *.<a href="http://facebook.com">facebook.com</a> *.<a href="http://twitter.com">twitter.com</a> *.<a href="http://files.com">files.com</a> *.<a href="http://gear.net">gear.net</a> <a href="http://video.tv">video.tv</a> *.<a href="http://video.tv">video.tv</a> <a href="http://videomedia.tv">videomedia.tv</a> <a href="http://www.videomedia.tv">www.videomedia.tv</a> <a href="http://embed.videomedia.tv">embed.videomedia.tv</a>;<br>
                if ($invalid_referer) {<br>                    return   403;<br>                }<br>                }<br><br> # pass the PHP scripts to FastCGI server listening on <a href="http://127.0.0.1:9000">127.0.0.1:9000</a><br>
        location ~ \.php$ {<br>            root /var/www/html/files;<br>            fastcgi_pass   <a href="http://127.0.0.1:9000">127.0.0.1:9000</a>;<br>           fastcgi_index  index.php;<br>            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;<br>
            include        fastcgi_params;<br>        }<br><br>        location ~ /\.ht {<br>            deny  all;<br>        }<br>}<br><br></div><div>EDGE :-<br><br>#proxy_ignore_headers "Set-Cookie";<br>proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=static:100m<br>
                        loader_threshold=200 loader_files=500 inactive=1d<br>                        max_size=62g;<br><br><br>server {<br><br>        listen       80;<br>        server_name  <a href="http://tw002.edge.com">tw002.edge.com</a>;<br>
        root /var/www/html/files;<br>        location ~ \.(mp4|jpeg|jpg)$ {<br>               root   /var/www/html/files;<br>                mp4;<br>                try_files $uri @getfrom_origin;<br><br>            }<br>
<br>   <br>        location @getfrom_origin {<br>        proxy_pass <a href="http://origin.files.com:80">http://origin.files.com:80</a>;<br>#       proxy_cache_valid 200 302   60m;<br>        proxy_cache_valid  15d;<br>        proxy_cache static;<br>
        proxy_cache_min_uses 1;<br>        }<br><br><br><br>}<br></div><br><div>Help will be highly appreciated.<br></div></div>