Varnish - HTTP Accelerator Crash Course
Ғылым және технология
Varnish is a reverse proxy web accelerator Written in C designed to improve HTTP performance by using server side caching.
In this video I’m going to go through how Varnish works, we will spin up a Varnish docker container and finally talk about the pros and cons of this tech.
Chapters
0:00 Intro
1:53 Classic HTTP Architecture
3:50 How Varnish Works
7:50 Demo HTTP
18:23 Demo HTTPS
28:43 Varnish Pros
39:26 Varnish Cons
Agenda
* Classic HTTP Architecture
* How Varnish Works?
* HTTP Setup - Varnish
* HTTPS Setup - Varnish with Caddy as TLS Terminator.
* Varnish Pros & Cons
* Summary
Pros
* Cache & prefetching documents
* Resolve DNS hostnames in documents
* Rewrite scripts to optimize code
* Load Balancing
* Backend Connection Pooling
* Varnish Modules (VMODS, e.g. rewrite headers)
* Edge side includes (personalized dynamic page)
Cons
* Cache Invalidation
* Only works on unencrypted HTTP
* For HTTPS frontend, terminate TLS
* For HTTPS backend, no solution in Varnish open source
* Can’t cache POST requests (e.g. GraphQL queries)
* HTTP/2 backends won’t benefit
docker commands
docker run --name varnish -p 8080:80 varnish
docker cp default.vcl varnish:/etc/varnish
default.vcl
vcl 4.0;
backend default {
.host = "husseinmac";
.port = "2015";
}
Cards:
Connection Pooling 2:15 • Connection Pooling in ...
Layer 4 vs Layer 7 Load balancing 6:25 • Load balancing in Laye...
GET vs POST 6:48 • When to use HTTP GET v...
Postgres NodeJS Chrome 8:23 • Building a Web API wit...
Redis 46:13 • Redis In-memory Databa...
TLS Termination 49:35 • SSL/TLS Termination, T...
Resources
edge side includes
www.fastly.com/blog/using-esi...
Cache invalidation varnish
www.smashingmagazine.com/2014...
Varnish Doc
varnish-cache.org/docs/
🏭 Software Architecture Videos
• Software Architecture
💾 Database Engineering Videos
• Database Engineering
🛰 Network Engineering Videos
• Network Engineering
🏰 Load Balancing and Proxies Videos
• Proxies
🐘 Postgres Videos
• PostgresSQL
🧮 Programming Pattern Videos
• Programming Patterns
🛡 Web Security Videos
• Web Security
🦠 HTTP Videos
• HTTP
🐍 Python Videos
• Python by Example
🔆 Javascript Videos
• Javascript by Example
Support me on PayPal
bit.ly/33ENps4
Become a Patreon
/ hnasr
Stay Awesome,
Hussein
Пікірлер: 49
Classic HTTP Architecture : 1:53 How Varnish Works 3:50 Demo HTTP 7:50 Demo HTTPS 18:23 Varnish Pros 28:43 Varnish Cons 39:26
Incredibly good beginners guide to Varnish. Great balance between basic and more advanced stuff. Thanks alot!
@hnasr
4 жыл бұрын
Robert Carlsson thanks Robert! Appreciate you
gets so happy: "I can refresh all day"
Only watched one video of yours so far but you're fantastic. Gonna check out more!
Just sharing some problems I ran into when doing this guide: If you run into "Error 503 Backend fetch failed" all the time, it may be because varnish cannot find your services that your run on localhost. If you are on Mac (may work on other OS too), you will have to type the following to connect to a service running on your own machine outside docker (where host.docker.interal will resolve to to where docker thinks your local machine is relative to its own network): backend default { .host = "host.docker.internal"; .port = "3007"; } This took me a long time to figure out so wanted to share it. Also, if you run into problems with the caching not working, make sure you are not sending cookies or setting no-cache headers in the request as this makes varnish not cache by default. Otherwise, thanks for a good video Hussein!
@martintopolanek448
4 ай бұрын
Thank you! You directed me to the right solution! I had to change port because my next.js app is by default launched on port 3000. So I needed to have following configuration: backend default { .host = "host.docker.internal"; .port = "3000"; }
I really like the way you talk about this stuff ;)
Bro Hussain, first of all, I would like to thank you for your efforts and the time you've spent to come out with this masterpiece channel. great job, it was very helpful indeed. Q) Don't you think that when we used different technologies from different authors working very similar things will cause data delay? speed is one of the important factors. I think one technology will achieve 4 tasks in 1 environment, for example, we can use Nginx to listen to port 80 and/or 443 terminations in the frontend as well as a load balancer + Caching in the backend. please correct me if I am wrong. Regards
Awesome awesome stuff. Amazing teacher you are Hussein
Really helpful ..thanks
Great video
Today I learned ❤❤❤
Perfect 👍👍👍 god bless you 🙏
@hnasr
4 жыл бұрын
Thanks Abdalla!
Thank you! Do you know how this could be combined with jwilder/nginx-proxy? I get a 503 error when I reach my server since Im using jwilder. Help would be greatly appreciated.
This is excellent sir
Hussein thanks for this tutorial it was helpful. Is there any way to trace varnish logs?
I am running a website on HTTP/2, was thinking of installing Varnish and came across your video. Just curious a bit further on the CONS site.. so if the server runs on HTTP/2, varnish has no benefit?
I am proud of you son.
finally u did it
@hnasr
4 жыл бұрын
Yes! you are one of the people who requested this video ALOT.. enjoy!
@rahulkumarsingh1716
4 жыл бұрын
@@hnasr what would be next video about? and when?
@hnasr
4 жыл бұрын
rahul kumar singh there is a video that went out today about spinning lightweight container that run Javascript code. Tomorrow’s video VPN vs Proxy
Danke!
What happened before 17:45 so that the timestamp changed with varnish too?
Great video, but personally I will go with Redis to have greater control as you said and by avoiding an extra hop for all the requests.
Can we use Varnish as cache proxy as frontend for docker registry? Hope varnish can cache docker images? If yes, is it feasible solution?
Teaching is an Art, and you dear sir, you are an ARTIST!
can we use varnish as youtube cache?
great video Hussein. Any idea what this would look like if we have four of the main web servers with an azure load balancer. Where does the varnish go into that design?
@pandaarmy9782
4 ай бұрын
Behind your loadbalancer would make the most sense, the LB can handle ssl termination and then forward requests to varnish, if you would use HAProxy as LB you would be able to do some really advanced stuff together with Varnish
Do you need Varnish if you have a configured CDN?
@hnasr
4 жыл бұрын
If the CDN does caching for you (which probably they do) then I think you don’t need it necessarily
Can you please make varnish -> nginx -> Apache configuration ? Thanks
Hey Hussein, do you recommend to use Apache + varnish or Apache + cloudflare?
@hnasr
4 жыл бұрын
Hey Wesley, I don’t have a strong opinion it depends on how much fine control you want. Cloudflare will take care of a lot of caching and optimization for you that You will have to manage manually with Varnish. Varnish will give you control and customization through VCL. One option is cheaper than the other
@wesleydevries7415
4 жыл бұрын
@@hnasr thank you a lot Hussein, my hoster for my shared hosting WordPress website has a special "WordPress" varnish settings and provides it for free. (In dutch: www.vimexx.nl/help/varnish-cache-inschakelen). Do you have an opinion in this specific case? :) Thank you a lot!
i need hep to built the right cache server
Bad for WP?
But varnish is like a thousand times faster than having your web server and libraries compile to run redis to return a response...
watch this in at least x1.5 for a better experience
Who is the certificate authority?
@hnasr
3 жыл бұрын
I talk about CA here kzread.info/dash/bejne/qpN9mLOcY5i2pbQ.html
@Stoney_Eagle
3 жыл бұрын
@@hnasr Thanks for replying, but I mean the authority of this https certificate. 😉
Hardest problem in computer science? Are you willing to repeat that claim in front of the audience in my theoretical computer science lecture hall? :D
So basically, it's just an ordinary reverse proxy like nginx/haproxy? But has a lot of limitations compared to them. Looks like a useless thing for me...