Advertisement
sufehmi

Setup Varnish on Port 80

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