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

  • @hnasr
    @hnasr4 жыл бұрын

    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

  • @robertcarlsson1781
    @robertcarlsson17814 жыл бұрын

    Incredibly good beginners guide to Varnish. Great balance between basic and more advanced stuff. Thanks alot!

  • @hnasr

    @hnasr

    4 жыл бұрын

    Robert Carlsson thanks Robert! Appreciate you

  • @0xedb
    @0xedb4 жыл бұрын

    gets so happy: "I can refresh all day"

  • @WilliamWolfrath
    @WilliamWolfrath2 жыл бұрын

    Only watched one video of yours so far but you're fantastic. Gonna check out more!

  • @arvidmildner6274
    @arvidmildner62743 жыл бұрын

    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

    @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"; }

  • @DamianMajewski
    @DamianMajewski2 жыл бұрын

    I really like the way you talk about this stuff ;)

  • @iQatif
    @iQatif3 жыл бұрын

    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

  • @adamcheung1232
    @adamcheung12323 жыл бұрын

    Awesome awesome stuff. Amazing teacher you are Hussein

  • @anirbandutta1371
    @anirbandutta13714 жыл бұрын

    Really helpful ..thanks

  • @jessebaker2861
    @jessebaker28614 жыл бұрын

    Great video

  • @whereismypipey
    @whereismypipey4 жыл бұрын

    Today I learned ❤❤❤

  • @abdallahdhaou3065
    @abdallahdhaou30654 жыл бұрын

    Perfect 👍👍👍 god bless you 🙏

  • @hnasr

    @hnasr

    4 жыл бұрын

    Thanks Abdalla!

  • @robertosoriano9617
    @robertosoriano96173 жыл бұрын

    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.

  • @joelachiana9912
    @joelachiana9912 Жыл бұрын

    This is excellent sir

  • @sarojakuncha6487
    @sarojakuncha64874 жыл бұрын

    Hussein thanks for this tutorial it was helpful. Is there any way to trace varnish logs?

  • @yoonssam_kr
    @yoonssam_kr3 жыл бұрын

    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?

  • @webdev723
    @webdev7233 жыл бұрын

    I am proud of you son.

  • @rahulkumarsingh1716
    @rahulkumarsingh17164 жыл бұрын

    finally u did it

  • @hnasr

    @hnasr

    4 жыл бұрын

    Yes! you are one of the people who requested this video ALOT.. enjoy!

  • @rahulkumarsingh1716

    @rahulkumarsingh1716

    4 жыл бұрын

    @@hnasr what would be next video about? and when?

  • @hnasr

    @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

  • @stadtner
    @stadtner2 жыл бұрын

    Danke!

  • @zsebacsi2
    @zsebacsi2 Жыл бұрын

    What happened before 17:45 so that the timestamp changed with varnish too?

  • @palaniappanrm6277
    @palaniappanrm62774 жыл бұрын

    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.

  • @Kavinnathcse
    @Kavinnathcse Жыл бұрын

    Can we use Varnish as cache proxy as frontend for docker registry? Hope varnish can cache docker images? If yes, is it feasible solution?

  • @ryanisthewind
    @ryanisthewind2 жыл бұрын

    Teaching is an Art, and you dear sir, you are an ARTIST!

  • @user-yr5rh7zc6e
    @user-yr5rh7zc6e2 жыл бұрын

    can we use varnish as youtube cache?

  • @markrawson1435
    @markrawson1435 Жыл бұрын

    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

    @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

  • @marfnl2
    @marfnl24 жыл бұрын

    Do you need Varnish if you have a configured CDN?

  • @hnasr

    @hnasr

    4 жыл бұрын

    If the CDN does caching for you (which probably they do) then I think you don’t need it necessarily

  • @ddrci88
    @ddrci882 жыл бұрын

    Can you please make varnish -> nginx -> Apache configuration ? Thanks

  • @wesleydevries7415
    @wesleydevries74154 жыл бұрын

    Hey Hussein, do you recommend to use Apache + varnish or Apache + cloudflare?

  • @hnasr

    @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

    @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!

  • @eliehaddad4908
    @eliehaddad49083 жыл бұрын

    i need hep to built the right cache server

  • @StefTechSurfer
    @StefTechSurfer3 жыл бұрын

    Bad for WP?

  • @Joe-jc5ol
    @Joe-jc5ol3 жыл бұрын

    But varnish is like a thousand times faster than having your web server and libraries compile to run redis to return a response...

  • @workshop1804
    @workshop18043 жыл бұрын

    watch this in at least x1.5 for a better experience

  • @Stoney_Eagle
    @Stoney_Eagle3 жыл бұрын

    Who is the certificate authority?

  • @hnasr

    @hnasr

    3 жыл бұрын

    I talk about CA here kzread.info/dash/bejne/qpN9mLOcY5i2pbQ.html

  • @Stoney_Eagle

    @Stoney_Eagle

    3 жыл бұрын

    @@hnasr Thanks for replying, but I mean the authority of this https certificate. 😉

  • @teckyify
    @teckyify2 жыл бұрын

    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

  • @user-jh1vx3vx1c
    @user-jh1vx3vx1c Жыл бұрын

    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...

Келесі