<div dir="ltr"><div>Hello itpp,i have been abled to use ngx_http_geo_module. Now the request coming from local ISP will first go to the main server (US) and then main server will check if the ip is 1.2.3.4 so it'll direct the request to the local caching server and than caching server will check if the file is cached or it should again get the file from main server and cache it locally.<br>
<br></div><div>When i tested it locally, it worked fine but the file URL in firebug is coming from MAIN server when it should have come from the local caching server. I can also see the caching directory size increases when the matching client via geo module is directed to the local caching server but the URL remains the same in firebug.<br>
<br></div><div>US config :-<br><br>geo $TW {<br> default 0;<br> <a href="http://192.168.1.0/24">192.168.1.0/24</a> 1;<br>}<br><br><br><br>server {<br> listen 80;<br> server_name <a href="http://002.files.com">002.files.com</a>;<br>
# limit_rate 600k;<br> location / {<br> root /var/www/html/files;<br> index index.html index.htm index.php;<br> # autoindex on;<br>}<br><br><br>location ~ \.(mp4|jpeg|jpg)$ {<br>
mp4;<br> root /var/www/html/files;<br><br> if ($TW) {<br> proxy_pass <a href="http://192.168.22.32:80">http://192.168.22.32:80</a>;<br> }<br>
<br> expires 7d;<br> valid_referers none blocked <a href="http://domain.com">domain.com</a> *.<a href="http://domain.com">domain.com</a> <a href="http://blog.domain.com">blog.domain.com</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://pump.net">pump.net</a> <a href="http://domain.tv">domain.tv</a> *.<a href="http://domain.tv">domain.tv</a> <a href="http://domainmedia.tv">domainmedia.tv</a> <a href="http://www.domainmedia.tv">www.domainmedia.tv</a> <a href="http://embed.domainmedia.tv">embed.domainmedia.tv</a>;<br>
if ($invalid_referer) {<br> return 403;<br> }<br> }<br>}<br><br></div><div>Edge config :-<br><br>proxy_ignore_headers "Set-Cookie";<br>proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=static:100m<br>
loader_threshold=300 loader_files=10 inactive=1d<br> max_size=300000m;<br><br><br>proxy_temp_path /data/nginx/tmp 1 2;<br>add_header X-Cache-Status $upstream_cache_status;<br>
add_header Accept-Ranges bytes;<br>max_ranges 512;<br><br><br><br>server {<br><br> listen 80;<br> server_name 192.168.22.32;<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://002.files.com:80">http://002.files.com:80</a>;<br>
proxy_cache_valid 200 302 60m;<br> proxy_cache_valid any 1m;<br> proxy_cache static;<br> proxy_cache_min_uses 1;<br> }<br><br><br></div><div>Maybe i need to add some variable to get original server ip ?<br>
<br><br></div><div><a href="http://nginx.org/en/docs/http/ngx_http_geo_module.html"><br></a></div><a href="http://nginx.org/en/docs/http/ngx_http_geo_module.html"></a></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Jun 6, 2014 at 8:56 PM, shahzaib shahzaib <span dir="ltr"><<a href="mailto:shahzaib.cb@gmail.com" target="_blank">shahzaib.cb@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Thanks a lot itpp. :) I'll look into it and get back to you. <br><br>Thanks again for quick solution :)<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Jun 6, 2014 at 8:26 PM, itpp2012 <span dir="ltr"><<a href="mailto:nginx-forum@nginx.us" target="_blank">nginx-forum@nginx.us</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">shahzaib1232 Wrote:<br>
-------------------------------------------------------<br>
<div>> @itpp I am currenlty proceeding with proxy_cache method just because i<br>
> had<br>
> to done this in emergency mode due to boss pressure :-|. I have a<br>
> quick<br>
> question, can i make nginx to cache files for specific clients ?<br>
><br>
> Like, if our caching servers are deployed by only single ISP named<br>
> "ptcl".<br>
> So if ip from ptcl client is browsing video, only his requested file<br>
> should<br>
> be cached not for any other client, does nginx support that ??<br>
<br>
</div>You could do this based on some IP ranges or via<br>
<a href="https://github.com/flant/nginx-http-rdns" target="_blank">https://github.com/flant/nginx-http-rdns</a><br>
<br>
See<br>
<a href="http://serverfault.com/questions/380642/nginx-how-to-redirect-users-with-certain-ip-to-special-page" target="_blank">http://serverfault.com/questions/380642/nginx-how-to-redirect-users-with-certain-ip-to-special-page</a><br>
and<br>
<a href="http://www.cyberciti.biz/faq/nginx-redirect-backend-traffic-based-upon-client-ip-address/" target="_blank">http://www.cyberciti.biz/faq/nginx-redirect-backend-traffic-based-upon-client-ip-address/</a><br>
<br>
Posted at Nginx Forum: <a href="http://forum.nginx.org/read.php?2,249997,250707#msg-250707" target="_blank">http://forum.nginx.org/read.php?2,249997,250707#msg-250707</a><br>
<div><div><br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>