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
Β
Β
Β
# 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
Comments
0 B
|π
/π
0 B
|π
/π
0 B
|π
/π
0 B
|π
/π
0 B
|π
/π
0 B
|π
/π
0 B
|π
/π
0 B
|π
/π
0 B
|π
/π
0 B
|π
/π