Sometimes you need to quickly setup Varnish, usually in an emergency (like, your website got featured on Reddit’s frontpage 😀 ), to quickly absorb most of the hits hitting your website.
But the webserver is already using port 80.
Now what ?
Pretty easy actually :
- Setup Varnish on other port, say, 6081
- Run an iptables command : to forward incoming traffic from port 80 to port 6081
- Make sure Varnish uses 127.0.0.1:80 as the backend
Presto – now all the traffic hits Varnish first – which will process them in lightning speed.
Alright, so here’s the gory detail, also available on Pastebin.com : https://pastebin.com/2UBD7s05
Enjoy !
========
apt-get update ; apt-get -y install varnish
# Varnish should be already configured to list on port 6081
# if in doubt, check /etc/default/varnish,
# and look for the following line :
# DAEMON_OPTS="-a :6081
# edit varnish config
vi /etc/varnish/default.vcl
# make sure the .port line is set to 80, like this :
# .port = "80";
# then save & exit
# enable Apache's expires & headers module
a2enmod expires
a2enmod headers
# setup caching for static files
# via .htaccess file
echo "Header unset ETag" >> /var/www/.htaccess
echo "FileETag None" >> /var/www/.htaccess
echo "<ifmodule mod_expires.c>" >> /var/www/.htaccess
echo "<filesmatch \"(?i)^.*\\.(ico|flv|jpg|jpeg|png|gif|js|css)$\">" >> /var/www/.htaccess
echo "ExpiresActive On" >> /var/www/.htaccess
echo "ExpiresDefault \"access plus 2 minute\"" >> /var/www/.htaccess
echo "</filesmatch>" >> /var/www/.htaccess
echo "</ifmodule>" >> /var/www/.htaccess
# enable caching in php.ini
vi /etc/php/7.0/apache2/php.ini
# make sure session.cache_limiter = public
# save & exit
# restart Apache
/etc/init.d/apache2 restart
###### now let's start forwarding traffic to Varnish ######
# enable port forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
vi /etc/sysctl.conf
# add this line at the end of the file :
# net.ipv4.ip_forward = 1
# now here's the command that will actually forward the traffic from port 80 to Varnish
# change eth0 to your computer's network interface name
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 6081
# make sure this iptables setting will become permanent
apt-get -y install iptables-persistent
Now here’s the command that will actually forward the traffic from port 80 to Varnish.
รับทำเว็บไซต์ เชียงใหม่
This entry was posted on Sunday, February 18th.
รับออกแบบ สติ๊กเกอร์ไลน์
beneran membuat kepala pening
memusingkan kepala aing
wow keren .nice
lieur bray euy
Cool bro, i will follow step by step your instruction
Thanks for your info
Felix Andika
Terima kasih infonya bos, sangat membantu sekali
Informasi yang menarik,, banyak pengetahuan yang dapat dipelajari di website ini..
You have remarked very interesting details ! ps nice site.
I beloved up to you’ll obtain performed proper here. The caricature is tasteful, your authored subject matter stylish. nevertheless, you command get bought an edginess over that you would like be delivering the following. sick indisputably come more in the past again since exactly the similar just about very often inside of case you shield this hike.
Heya! I’m at work browsing your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the superb work!
Thank you for sharing your idea. It’s great:D
Nice post. I was checking constantly this weblog and I’m inspired!
Thank you so much for the info that you have to say, because there inforamasi which provide very useful
thnaks for all this formation is awsome
Nice info. This is a very impressive post, Very useful information, it clarified things a lot for us. Thanks for sharing valuable tips. – Shirdi Flight packages from Chennai
keren broo
https://kriptova.com
I found this post as very useful , you have tried to explain things very beautifully . Keep up the good job.
Thanks
DedicatedHosting4u.com
nice post lads Thank for ur post