tataweb

YouTube Caching Using Squid & Nginx

Must read:

Ferdian Alfianto

Ferdian Alfianto

Ferdian Alfianto is an Internet enthusiast, Mac Lover; likes using Wordpress, experimenting with Linux (especially Debian and Ubuntu), tinkering with pfSense routers, happy experimenting with LEMP (Linux, Nginx, MariaDB, PHP) and Redis. You can contact me here.

Honestly, it's almost impossible for us to caching all the videos that are on YouTube. But by caching videos that are accessed by many users, it will automatically be enough to help save our Internet bandwidth.

NOTE:

  • I took this tutorial from his blog Syed Jahanzaib, but I tweaked it a little to match the OS I use, namely Debian 7 (Wheezy).
  • I do not guarantee this tutorial can run 100% because sometimes Youtube changes the url of the video, so in the future it may need improvement & tweaking.

Next we will go to the installation process.

Installation Steps

I assume you already have a server with OS Debian 7 (Wheezy) installed, either 32bit or 64bit doesn't matter. (Note: It is possible that this tutorial can also be used on Ubuntu Server OS, but since I have never tried it, I cannot guarantee its success).

Our first step will be to update & upgrade the Debian component with the following command:

apt-get update && apt-get upgrade

And then we install Squid with the command:

apt-get install squid

Note: here we are using Squid version 2.7.STABLE9-4.1

Then we backup the default configuration of Squid with the command:

mv /etc/squid/squid.conf /etc/squid/squid.conf.old

And let's create our own customized Squid configuration for caching YouTube videos:

nano /etc/squid/squid.conf

And enter the following configuration:

Save & exit nano with Ctrl + O and Ctrl + X commands

Next we will install Nginx with the command:

apt-get install nginx

We backup the default nginx.conf configuration with the following command:

mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old

then we enter the new nginx.conf with the command

nano /etc/nginx/nginx.conf

and enter the following configuration:

Save & exit nano with Ctrl + O and Ctrl + X commands

Next we create a directory to store cache files:

mkdir / usr / local / www
mkdir / usr / local / www / nginx_cache
mkdir / usr / local / www / nginx_cache / tmp
mkdir / usr / local / www / nginx_cache / files
chown www-data / usr / local / www / nginx_cache / files / -Rf

Then we create the nginx.rb file with the command:

touch /etc/nginx/nginx.rb
chmod 755 /etc/nginx/nginx.rb
nano /etc/nginx/nginx.rb

and enter the following configuration:

Save & exit nano with Ctrl + O and Ctrl + X commands

Then we install Ruby with the command:

apt-get install ruby

And we create a directory to store the Squid cache:

mkdir / cache
chown proxy: proxy / cache
chmod -R 777 / cache

Run Squid to create a cache directory with the command:

squid -z

And the final step is to run squid & nginx:

service squid start
service nginx restart

To view cached videos, run the command:

ls -lh / usr / local / www / nginx_cache / files

You can see a demo of the results before and after caching in the following video:

Share on facebook
Facebook
Share on twitter
Twitter
Share on whatsapp
WhatsApp
Share on telegram
Telegram
Share on email
E-mail

Latest articles:

MongoDB logo
Linux

Easy to Install MongoDB on Ubuntu 20.04

This tutorial explains how to install and configure MongoDB Community Edition on Ubuntu 20.04. MongoDB is a free, open-source document database. Belongs to the so-called database family

Related article:

MongoDB logo

Easy to Install MongoDB on Ubuntu 20.04

This tutorial explains how to install and configure MongoDB Community Edition on Ubuntu 20.04. MongoDB is a free, open-source document database. Belongs to the so-called database family

www

World's First Website

On 6 August 1991, without fanfare, British computer scientist Tim Berners-Lee published his first website while working at CERN, the large particle physics laboratory.