sufehmi

Setup Varnish on Port 80

Feb 18th, 2018 (edited)
2,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.50 KB | None | 0 0
  1. apt-get update ; apt-get -y install varnish
  2.  
  3. # Varnish should be already configured to list on port 6081
  4. # if in doubt, check /etc/default/varnish,
  5. # and look for the following line :
  6. #       DAEMON_OPTS="-a :6081
  7.  
  8.  
  9.  
  10. # enable Apache's expires & headers module
  11. a2enmod  expires
  12. a2enmod  headers
  13.  
  14. # setup caching for static files
  15. # via .htaccess file
  16. echo "Header unset ETag" >> /var/www/.htaccess
  17. echo "FileETag None" >> /var/www/.htaccess
  18. echo "<ifmodule mod_expires.c>" >> /var/www/.htaccess
  19. echo "<filesmatch \"(?i)^.*\\.(ico|flv|jpg|jpeg|png|gif|js|css)$\">" >> /var/www/.htaccess
  20. echo "ExpiresActive On" >> /var/www/.htaccess
  21. echo "ExpiresDefault \"access plus 2 minute\"" >> /var/www/.htaccess
  22. echo "</filesmatch>" >> /var/www/.htaccess
  23. echo "</ifmodule>" >> /var/www/.htaccess
  24.  
  25. # enable caching in php.ini
  26. vi /etc/php/7.0/apache2/php.ini
  27.  
  28. # make sure session.cache_limiter = public
  29. # save & exit
  30.  
  31. # restart Apache
  32. /etc/init.d/apache2 restart
  33.  
  34. ###### now let's start forwarding traffic to Varnish ######
  35.  
  36. # enable port forwarding
  37. echo 1 > /proc/sys/net/ipv4/ip_forward
  38. vi /etc/sysctl.conf
  39.  
  40. # add this line at the end of the file :
  41. # net.ipv4.ip_forward = 1
  42.  
  43. # now here's the command that will actually forward the traffic from port 80 to Varnish
  44. # change eth0 to your computer's network interface name
  45. iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 6081
  46.  
  47. # make sure this iptables setting will become permanent
  48. apt-get -y install iptables-persistent
Advertisement
Add Comment
Please, Sign In to add comment