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 "" >> /var/www/.htaccess echo "" >> /var/www/.htaccess echo "ExpiresActive On" >> /var/www/.htaccess echo "ExpiresDefault \"access plus 2 minute\"" >> /var/www/.htaccess echo "" >> /var/www/.htaccess echo "" >> /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