Dengan melakukan cache video, image, pada web site yang sering di buka seperti cache youtube, cache facebook dan lain sebagai nya. Squid Proxy yang sudah di bangun akan lebih maksimal dalam hal penghematan bandwidth dan mempercepat saat browsing.
Untuk kali ini DSI akan berbagi tutorial Cache Youtube Video dengan Squid Proxy sesuai janji DSI pada artikel sebelumnya.
Masalah Cache YouTube
CDN ( Content Delivery Network) Youtube
Youtube mempunyai server cadangan di beberapa negara. Agar video youtube mudah dan cepat saat di akses oleh semua pengunjung di dunia. Pengunjung akan di respond dari server yang paling dekat dengan negara nya.
Dynamic URL Youtube
Url video youtube selalu ber ubah – ubah (Dinamis). Sebagai contoh lihat url video dari gambar berikut:
Solusi supaya url youtube menjadi statis (tetap) dan bisa di cache harus menggunakan “STORE-ID”. Sehingga dengan url yang statis maka squid dapat melakukan cache youtube.
Youtube Mengunakan Port 443 (HTTPS)
Untuk melakukan cache youtube anda harus meng install squid yang sudah support dengan web https.
STORE-ID Youtube
Sekilas STORE-ID, berfungsi menulis ulang url yang masuk ke dalam helper store-id menjadi url yang tetap (statis). Helper Store-id dapat di tulis dengan bahasa pemrograman seperti perl, php, Python dan lain sebagai nya.
Di sini DSI akan memberikan script store-id untuk cache youtube menggunakan bahasa program perl.
- Buka program putty dan login menggunan user root.
- Buat file perl dan berikan nama “store-id.pl” pada directory “/etc/squid/”
touch /etc/squid/store-id.pl
- Beri permision / akses ijin file store-id
chmod 777 /etc/squid/store-id.pl
chown -R proxy:proxy /etc/squid/store-id.pl
- Masukan Script di bawah ini pada file “store-id.pl” yang sudah di buat tadi.
#!/usr/bin/perl
# =====================================================
# = DSI store-id sample youtube 2016
# = https://www.facebook.com/R.dhani.dhanu
# = https://www.dokter-squid.com/
# =====================================================
$|=1;
while (<>) {
chomp;
my $dsi = "";
if (s/^(\d+\s+)//o) { $dsi = $1; }
@X = split;
if (@X[0] =~ m/^(exit|quit|x|q)/) {
print STDERR "quiting helper quietly\n";
exit 0;
}
$url = $X[0];
$referer = $X[1];
# youtube.com
if ($url =~ m/^https?:\/\/.*\.googlevideo\.com\/videoplayback\?.*/) {
@id = m/[\&?|\%?|\s?]id=([^\&\%\s]+)/;
@range = m/[\&?|\%?|\s?]range=([^\&\%\s]+)/;
@itag = m/[\&?|\%?|\s?]itag=([^\&\%\s]+)/;
@mime = m/[\&?|\%?|\s?]mime=([^\&\%\s]+)/;
@clen = m/[\&?|\%?|\s?]clen=([^\&\%\s]+)/;
if ($referer =~ m/^https?\:\/\/www\.youtube\.com\/(watch\?v\=|embed\/|v\/)(.*)/) {
$v = $2;
} else { $v = $id[0] }
$out = "http://youtube.dokter-squid.com/" . $v . "@range@itag@mime@clen";
# ytimg.com
} elsif ($url =~ m/^https?:\/\/.*\.ytimg\.com(.*\.(webp|jpg|gif))/) {
$out = "http://ytimg.dokter-squid.com/$1";
} else {
$out = "ERR";
}
if ($out =~ m/^http:\/\/.*/) {
print $dsi, "OK store-id=$out\n";
} else {
print $dsi, "ERR\n";
}
}
- Buka “squid.conf” lalu tambahkan script di bawah ini:
acl youtube url_regex -i ^https?:\/\/.*\.googlevideo\.com\/videoplayback\?
acl youtube url_regex -i ^https?:\/\/.*\.ytimg\.com.*\.(webp|jpg|gif)
store_id_program /etc/squid/store-id.pl
store_id_extras "%{Referer}>h"
store_id_children 10 startup=5 idle=2 concurrency=100
store_id_access allow youtube
store_id_access deny all
refresh_pattern -i ^http.*\.dokter\-squid\.com 432000 100% 432000 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-store ignore-private ignore-auth ignore-must-revalidate
- Setelah kita menambahkan script “store-id” dan edit “squid.conf” sekarang saat nya lakukan “reconfigure”:
squid -k reconfigure
Sampai di sini jika tidak ada informasi “error” maka kita sudah berhasil membuat store-id untuk cache youtube. Silahkan di coba ulang kembali jika saat “reconfigure” terdapat informasi “error”.
Sekarang saatnya uji coba, apakah youtube berhasil di cache atau tidak dengan store-id di atas. Berikut contoh “access.log” video youtube yang sudah berhasil di cache dengan store-id diatas:
Demikian cara cache youtube dengan squid 3, semoga dengan tutorial ini pembaca sudah bisa melakukan cache youtube pada mesin proxy nya.
Bagi yang masih bingung dan malas untuk oprek, kami membuka Jasa Setting Proxy lewat remote, harga bersahabat dan bergaransi.
Jangan lupa subscribe dan Share jika anda merasa terbantu dan suka dengan artikel ini.
Terimakasih
gan, punya ane kok TCP_MEM_HIT semua yak ?
boleh dijelaskan dimana salahnya ?
errornya sih kagak ada gan.
tapi untuk youtubenya TCP_MISS
store_id_children 10 startup=5 idle=2 concurrency=100
this is the problem, if i enable this config on my squid.conf
don´t work
don´t open http or https..
if i disable this function it all work http and https
but no mem hit only TCP_TUNNEL/200
1468545186.243 66905 192.168.1.179 TCP_TUNNEL/200 5798 CONNECT l.ghostery.com:443 – HIER_DIRECT/54.209.100.134 –
1468545186.247 66947 192.168.1.179 TCP_TUNNEL/200 5798 CONNECT l.ghostery.com:443 – HIER_DIRECT/54.209.100.134 –
1468545186.247 66916 192.168.1.179 TCP_TUNNEL/200 5798 CONNECT l.ghostery.com:443 – HIER_DIRECT/54.209.100.134 –
1468545186.254 66961 192.168.1.179 TCP_TUNNEL/200 5798 CONNECT l.ghostery.com:443 – HIER_DIRECT/54.209.100.134 –
1468545186.256 67016 192.168.1.179 TCP_TUNNEL/200 5622 CONNECT l.ghostery.com:443 – HIER_DIRECT/54.209.100.134 –
1468545200.078 158456 192.168.1.179 TCP_TUNNEL/200 8262 CONNECT l.ghostery.com:443 – HIER_DIRECT/52.206.84.40 –
1468545229.064 103193 192.168.1.179 TCP_TUNNEL/200 12970611 CONNECT r3—sn-bxpbiucg51pa-btoe.googlevideo.com:443 – HIER_DIRECT/179.96.24.142 –
1468545233.965 107253 192.168.1.179 TCP_TUNNEL/200 11554255 CONNECT r3—sn-bxpbiucg51pa-btoe.googlevideo.com:443 – HIER_DIRECT/179.96.24.142 –
1468545267.246 66834 192.168.1.179 TCP_TUNNEL/200 344 CONNECT l.ghostery.com:443 – HIER_DIRECT/54.209.100.134 –
Btw i am using squid 3.5.20 with openssl 1.0.2h
Error if enabled in squid.conf
“store_id_children 10 idle startup = 5 = 2 concurrency = 100”
any idea why this is giving me error?
also when i enable in my webrowser google chrome proxy config for testing with output http port = 3128 and https = 3127 and i imported my cert.der inside google chrome ssl certificate.
i still get error trying to open https://google.com or https://youtube.com
warning your connection is not secure
NET::ERR_CERT_AUTHORITY_INVALID
and HTTPS do not work, only http on port 3128
Btw i am using your config from example squid https sslbump part2
and also youtube cache store-id.pl script.
any information i am missing?
what about https reflector have your heard about it, do you know how this works?
Ok thanks
working now http_port 3127 ssl bum
i was importing certificate myCA.pem in wrong folder, need to import in trusted root ca authoroties folder to make it work 😉
now opening port 3127 for https
Gan mau tanya kalau dihubungkan sama mikrotik konfigurasi nya gimana ya ??
new bie gan 😀
bisa gan… bisa cek di blog ini, ada tutorial lengkap mengenai squid transparent
Oh iya Makasih gan .. Sangat bermanfaat 😉
Permisi pak,
Saya ada error untuk httpsnya
TCP_DENIED/200 0 CONNECT 11.16.0.87:3129 – HIER_NONE/- –
saya manual dari set broser ke 3129 untuk https
untuk http normal di port 3128
terima kasih
ini masih berfungsi kh mas admin buat cache yuotube ????
ini klo mau buat cache yutub ikutin tutornya dari part2 dan cahe yutub ini bisa ??? tanpa perlu mengikuti yg part 1nya
Halo gan,thanks tutor nya..sangat bermanfaat..
btw untuk cache file .exe,rar,iso dll apa yang harus ditambahkan yaa?
bisa ia dan bisa ga juga gan, karena config yang saya berikan disini masih standar
Tutorialnya sangat bermanfaat sekali, terimakasih DSI.
saya tanya, jika di setting transparant kemudian ssl tidak diinput di masing2 browser apa yang terjadi?
terimakasih gan..
untuk ssl masih wajib install sertifikat ke dalam browser untuk squid cache https
1477718144.041 133711 192.168.10.100 TCP_TUNNEL/200 55800 CONNECT http://www.youtube.com:443 – HIER_DIRECT/74.125.200.91 –
1477718149.025 142813 192.168.10.100 TCP_TUNNEL/200 31999 CONNECT http://www.youtube.com:443 – HIER_DIRECT/74.125.200.91 –
1477718149.026 125894 192.168.10.100 TCP_TUNNEL/200 25300 CONNECT googleads.g.doubleclick.net:443 – HIER_DIRECT/172.217.27.2 –
1477718150.032 133566 192.168.10.100 TCP_TUNNEL/200 5625 CONNECT googleads.g.doubleclick.net:443 – HIER_DIRECT/172.217.27.2 –
1477718154.030 124637 192.168.10.100 TCP_TUNNEL/200 5183 CONNECT clients6.google.com:443 – HIER_DIRECT/74.125.200.113 –
1477718154.031 125018 192.168.10.100 TCP_TUNNEL/200 4084 CONNECT cm.g.doubleclick.net:443 – HIER_DIRECT/74.125.130.157 –
apakah log seperti diatas sudah berjalan dengan semestinya?