YouTube Caching Using Squid & Nginx


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.

NOTES:


  • 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 e-mail

E-mail

.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *