<div dir="ltr"><div><div><div><div><div>@RR, i've prepared the local environment with the following structure :-<br><br></div>client --> nginx (edge) --> varnish --> backend (Origin)<br><br></div>When i tested this method i.e :-<br><br></div>3 clients requested for test.mp4 (file size is 4mb) --> nginx --> file not existed (proxy_store) --> varnish --> backend (fetch the file from origin).<br><br></div>When nginx proxied these three requests subsequently towards the varnish,, despite of filling 4mb of tmp dir it was filled with 12MB which means nginx is proxying all three requests towards the varnish server and creating tmp files as long as the file is not downloaded. (The method was failed)<br><br></div><div>Although On putting varnish in front of nginx solved this issue. <br><br></div><div>3 clients requested for test.mp4(file size is 4mb) --> varnish(proxying all requests for mp4,jpg) --> nginx.(fetch the file from origin).<br><br></div><div>This time tmp dir was filled with the size of 4Mb which means varnish combined those 3 subsequent requests into 1.<br><br>--------------------------------------------------------------------------------------------------------------------------<br><br></div><div>Now varnish also has a flaw to send subsequent requests for same file towards the nginx i.e<br><br></div><div>1st user requested for file <a href="http://edge.files.com/videos/test.mp4">http://edge.files.com/videos/test.mp4</a>. During the downloading of first requested file, the second user also requested the same file but with random seeking <a href="http://edge.files.com/videos/test.mp4?start=33">http://edge.files.com/videos/test.mp4?start=33</a> . Now as the request uri is changed, there are two different requests for the same file in varnish and again nginx tmp directory was filled with 8MB instead of 4 which means nginx downloaded the full file twice. So Random seeking will only work once the file is cached locally, otherwise nginx will keep on creating tmp files against random seekings. <br><br></div><div>I have two questions now :-<br><br></div><div>1. If there's way to prevent duplicate downloads for random seekings while the file not downloaded yet ? Note :- We cannot disable mp4 module.<br></div><div>2. Should nginx in front of varnish never work as expected or i am doing something wrong ?<br><br></div><div>Following are existing varnish in front of nginx configs. Please let me know if something need to be fixed :-<br><br></div><div>varnish config :-<br><br>backend origin002 {<br> .host = "127.0.0.1";<br> .port = "8080";<br>}<br><br>backend origin003 {<br> .host = "127.0.0.1";<br> .port = "8080";<br>}<br><br><br>sub vcl_recv {<br> <br> if ( req.http.host == "<a href="http://origin002.files.com">origin002.files.com</a>" ){<br> set req.backend_hint = origin002;<br> } elsif ( req.http.host == "<a href="http://origin003.files.com">origin003.files.com</a>" ){<br> set req.backend_hint = origin003;<br> } elsif ( req.http.host == "<a href="http://origin004.files.com">origin004.files.com</a>" ){<br> set req.backend_hint = origin004;<br> } <br><br>}<br><br>sub vcl_backend_response {<br> <br><br>if (bereq.url ~ "^[^?]*\.(mp4|jpeg|jpg)(\?.*)?$"){<br> set beresp.do_stream = true;<br> return (deliver);<br>}<br>set beresp.grace = 1m;<br><br> return (deliver);<br><br><br>}<br><br>sub vcl_deliver {<br> <br>}<br><br></div><div>-----------------------------------------------------------------------------------------<br></div><div>Nginx config :-<br><br><br></div><div>server {<br><br> listen <a href="http://127.0.0.1:8080">127.0.0.1:8080</a>;<br> server_name <a href="http://origin002.files.com">origin002.files.com</a>;<br> root /var/www/html/tunefiles;<br> location ~ \.(mp4|jpeg|jpg)$ {<br> root /var/www/html/tunefiles;<br> mp4;<br> error_page 404 = @fetch;<br><br> }<br><br><br> location ~ \.(php)$ {<br> proxy_pass <a href="http://origin002.files.com:80">http://origin002.files.com:80</a>;<br> }<br><br><br><br> location @fetch {<br> internal;<br> proxy_max_temp_file_size 0;<br> proxy_pass http://content.files.com:80$uri;<br> proxy_store on;<br> proxy_store_access user:rw group:rw all:r;<br> root /var/www/html/tunefiles;<br>}<br><br>}<br><br><br></div><div> I can also send the configs which were configured for nginx in front of varnish (which didn't resolved my issue).<br><br></div><div>BTW, i am using malloc storage instead of file in varnish.<br></div><div><br></div><div>Thanks !!<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 24, 2014 at 6:55 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">@RR, That's great. Sure it will help me. I am starting to work with it on local environment and will get back to you once the progress started :)<br><br>Thanks a lot for writing sample config for me !!<br></div><div class=""><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 24, 2014 at 6:32 PM, Reinis Rozitis <span dir="ltr"><<a href="mailto:r@roze.lv" target="_blank">r@roze.lv</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
@RR. could you guide me a bit on it or point me to some guide to start with. I have worked with varnish regarding php caching so i have the basic knowledge of varnish but i am just not getting on how to make it work with proxy_store. :(<br>
</blockquote>
<br></span>
Depending on your needs (for example SSL) you can put varnish in different places in the setup:<br>
<br>
<br>
If you use SSL (which varnish itself doesn't support) you can use your proxy_store server as an SSL offloader:<br>
<br>
1. [client] <- -> [nginx proxy_store server] <- -> [varnish] <- -> [content_server]<br>
<br>
.. in this case when multiple requests land onto nginx proxy_store in case the file locally doesnt exist those are forwarded to varnish and combined into a single request to the content server.<br>
<br>
A simplistic/generic nginx config:<br>
<br>
location / {<br>
error_page 404 = @store;<br>
}<br>
<br>
location @store {<br>
internal;<br>
proxy_pass <a href="http://imgstore" target="_blank">http://imgstore</a>;;<br>
proxy_store on;<br>
}<br>
<br>
<br>
varnish config:<br>
<br>
backend default {<br>
.host = "content_server.ip";<br>
}<br>
sub vcl_recv {<br>
set req.backend = default;<br>
}<br>
<br>
<br>
Obviously add whatever else you need (like forwarded-for headers to pass the real client ip, cache expire times etc).<br>
<br>
<br>
<br>
2. In case you don't use SSL:<br>
<br>
[client] <- -> [varnish] <- -> [content_server]<br>
(optionally you put nginx or some other software like stud or pound on top of varnish as SSL offloader (personally I use Shrpx from Spdylay ( <a href="https://github.com/tatsuhiro-t/spdylay" target="_blank">https://github.com/tatsuhiro-<u></u>t/spdylay</a> ))<br>
<br>
Then generic varnish config would look bassically the same:<br>
<br>
backend default {<br>
.host = "content_server.ip";<br>
}<br>
sub vcl_recv {<br>
set req.backend = default;<br>
}<br>
<br>
sub vcl_backend_response {<br>
set beresp.do_stream = true;<br>
}<br>
<br>
<br>
<br>
Hope that helps.<div><div><br>
<br>
rr <br>
______________________________<u></u>_________________<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/<u></u>mailman/listinfo/nginx</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>