From 9cfb192dc54084615ba1653adee284e96bcd0b91 Mon Sep 17 00:00:00 2001 From: "C.Lee Taylor" Date: Mon, 13 Apr 2015 18:15:00 +0200 Subject: [PATCH] Add basic varnish support --- Vagrantfile | 11 ++++++++ readme.md | 2 ++ scripts/varnish.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 scripts/varnish.sh diff --git a/Vagrantfile b/Vagrantfile index f5ae5bac..a28eada0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -65,6 +65,10 @@ laravel_root_folder = "/vagrant/laravel" # Where to install Laravel. Will `com laravel_version = "latest-stable" # If you need a specific version of Laravel, set it here symfony_root_folder = "/vagrant/symfony" # Where to install Symfony. +# HTTP Reverse Proxy +varnish_version = "4" # Options: 3 | 4 +varnish_port_update = "true" # Update varnish port to 80 and apache/nginx to port 8080 + nodejs_version = "latest" # By default "latest" will equal the latest stable version nodejs_packages = [ # List any global NodeJS packages that you want to install #"grunt-cli", @@ -200,6 +204,13 @@ Vagrant.configure("2") do |config| # Provision Nginx Base # config.vm.provision "shell", path: "#{github_url}/scripts/nginx.sh", args: [server_ip, public_folder, hostname, github_url] + #### + # Reverse Proxy Servers + ########## + + # Provision Varnish + # config.vm.provision "shell", path: "#{github_url}/scripts/varnish.sh", args: [varnish_version, varnish_port_update] + #### # Databases diff --git a/readme.md b/readme.md index 9fd304fc..bfe25ff0 100644 --- a/readme.md +++ b/readme.md @@ -80,6 +80,8 @@ Here's a quickstart screencast! * Apache * HHVM * Nginx +* HTTP Reverse Proxy / Web Application Accelerator + * Varnish * Databases * Couchbase * CouchDB diff --git a/scripts/varnish.sh b/scripts/varnish.sh new file mode 100644 index 00000000..49dabfb7 --- /dev/null +++ b/scripts/varnish.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +echo ">>> Installing Varnish Server $1 ..." + +# Check if varnish source list +if [ -e /etc/apt/sources.list.d/varnish-cache.list ]; then + echo "Varnish repo already installed" + +else + echo "Installing Varnish repo ..." + curl https://repo.varnish-cache.org/GPG-key.txt | sudo apt-key add - + + # Could use Distro Release? + cat << EOF | sudo tee /etc/apt/sources.list.d/varnish-cache.list +# https://www.varnish-cache.org/installation/ubuntu +deb https://repo.varnish-cache.org/ubuntu/ trusty varnish-$1.0 +EOF + + sudo apt-get -qq install apt-transport-https + # Update Again + sudo apt-get update + +fi + +# Install varnish Server +# -qq implies -y --force-yes +sudo apt-get -qq install varnish + +# ToDo - Check dependencies / Change ports for Web Server + +# Update Web server and Varnish link +if [ $2 == "true" ]; then + + nginx -v > /dev/null 2>&1 + NGINX_IS_INSTALLED=$? + + apache2 -v > /dev/null 2>&1 + APACHE_IS_INSTALLED=$? + + # Set and enable configuration for Apache + if [ $APACHE_IS_INSTALLED -eq 0 ]; then + # Change the port Apache listens on from 80 to 8080 + sudo sed -i 's/^Listen\ 80$/Listen\ 8080/' /etc/apache2/ports.conf + + # Reload Apache to load in configuration + sudo service apache2 reload + fi + + # Set and enable configuration for Nginx + if [ $NGINX_IS_INSTALLED -eq 0 ]; then + # Change the port Nginx listens on from 80 to 8080 for all enabled sites + sudo sed -i 's/listen\ 80;$/listen\ 8080;/' /etc/nginx/sites-enabled/* + + # Reload Nginx to load in configuration + sudo service nginx reload + fi + + # Set Varnish to listen on port 80 +# DAEMON_OPTS="-a :6081 \ +# -T localhost:6082 \ +# -f /etc/varnish/default.vcl \ +# -S /etc/varnish/secret \ +# -s malloc,256m" + sudo sed -i.ssk 's/^DAEMON_OPTS=\"-a\ :6081\ \\$/DAEMON_OPTS=\"-a\ :80\ \\/' /etc/default/varnish + sudo service varnish restart +fi + +echo ">>> Installed Varnish Server $1 <<<"