Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added complete example to use varnish-geoip
- Loading branch information
Showing
5 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This examples are for Debian-like systems | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Configuration file for varnish | ||
# | ||
# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK | ||
# to be set from this shell script fragment. | ||
# | ||
|
||
# Should we start varnishd at boot? Set to "yes" to enable. | ||
START=yes | ||
|
||
# Maximum number of open files (for ulimit -n) | ||
NFILES=131072 | ||
|
||
# Maximum locked memory size (for ulimit -l) | ||
# Used for locking the shared memory log in memory. If you increase log size, | ||
# you need to increase this number as well | ||
MEMLOCK=82000 | ||
|
||
# Default varnish instance name is the local nodename. Can be overridden with | ||
# the -n switch, to have more instances on a single server. | ||
INSTANCE=$(uname -n) | ||
|
||
# Example options to allow compilation with GeoIP | ||
DAEMON_OPTS="-a :6081 \ | ||
-T localhost:6082 \ | ||
-f /etc/varnish/default.vcl \ | ||
-S /etc/varnish/secret \ | ||
-s malloc,100M \ | ||
-p 'cc_command=exec cc -fpic -shared -Wl,-x -L/usr/include/GeoIP.h -lGeoIP -o $@'" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#! /bin/sh | ||
|
||
### BEGIN INIT INFO | ||
# Provides: varnish | ||
# Required-Start: $local_fs $remote_fs $network | ||
# Required-Stop: $local_fs $remote_fs $network | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: Start HTTP accelerator | ||
# Description: This script provides a server-side cache | ||
# to be run in front of a httpd and should | ||
# listen on port 80 on a properly configured | ||
# system | ||
### END INIT INFO | ||
|
||
# Source function library | ||
. /lib/lsb/init-functions | ||
|
||
NAME=varnishd | ||
DESC="HTTP accelerator" | ||
PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
DAEMON=/usr/sbin/varnishd | ||
PIDFILE=/var/run/$NAME.pid | ||
|
||
test -x $DAEMON || exit 0 | ||
|
||
# Include varnish defaults if available | ||
if [ -f /etc/default/varnish ] ; then | ||
. /etc/default/varnish | ||
fi | ||
|
||
# Open files (usually 1024, which is way too small for varnish) | ||
ulimit -n ${NFILES:-131072} | ||
|
||
# Maxiumum locked memory size for shared memory log | ||
ulimit -l ${MEMLOCK:-82000} | ||
|
||
# If $DAEMON_OPTS is not set at all in /etc/default/varnish, use minimal useful | ||
# defaults (Backend at localhost:8080, a common place to put a locally | ||
# installed application server.) | ||
DAEMON_OPTS=${DAEMON_OPTS:--b localhost} | ||
|
||
# Ensure we have a PATH | ||
export PATH="${PATH:+$PATH:}/usr/sbin:/usr/bin:/sbin:/bin" | ||
|
||
start_varnishd() { | ||
log_daemon_msg "Starting $DESC" "$NAME" | ||
output=$(/bin/tempfile -s.varnish) | ||
if bash -c "start-stop-daemon \ | ||
--start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- \ | ||
-P ${PIDFILE} ${DAEMON_OPTS} > ${output} 2>&1"; then | ||
log_end_msg 0 | ||
else | ||
log_end_msg 1 | ||
cat $output | ||
exit 1 | ||
fi | ||
rm $output | ||
} | ||
|
||
disabled_varnishd() { | ||
log_daemon_msg "Not starting $DESC" "$NAME" | ||
log_progress_msg "disabled in /etc/default/varnish" | ||
log_end_msg 0 | ||
} | ||
|
||
stop_varnishd() { | ||
log_daemon_msg "Stopping $DESC" "$NAME" | ||
if start-stop-daemon \ | ||
--stop --quiet --pidfile $PIDFILE --retry 10 \ | ||
--exec $DAEMON; then | ||
log_end_msg 0 | ||
else | ||
log_end_msg 1 | ||
fi | ||
} | ||
|
||
reload_varnishd() { | ||
log_daemon_msg "Reloading $DESC" "$NAME" | ||
if /usr/share/varnish/reload-vcl -q; then | ||
log_end_msg 0 | ||
else | ||
log_end_msg 1 | ||
fi | ||
} | ||
|
||
status_varnishd() { | ||
status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}" | ||
} | ||
|
||
case "$1" in | ||
start) | ||
case "${START:-}" in | ||
[Yy]es|[Yy]|1|[Tt]|[Tt]rue) | ||
start_varnishd | ||
;; | ||
*) | ||
disabled_varnishd | ||
;; | ||
esac | ||
;; | ||
stop) | ||
stop_varnishd | ||
;; | ||
reload) | ||
reload_varnishd | ||
;; | ||
status) | ||
status_varnishd | ||
;; | ||
restart|force-reload) | ||
$0 stop | ||
$0 start | ||
;; | ||
*) | ||
log_success_msg "Usage: $0 {start|stop|restart|force-reload}" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
include "/etc/varnish/geoip.vcl"; | ||
|
||
backend default { | ||
.host = "localhost"; | ||
.port = "8080"; | ||
} | ||
|
||
sub vcl_recv { | ||
|
||
# Lookup IP only for the first request restart | ||
if (req.restarts == 0) { | ||
if (req.request == "GET" || req.request == "POST") { | ||
C{ | ||
vcl_geoip_set_header(sp); | ||
}C | ||
} | ||
} | ||
|
||
} | ||
|
||
sub vcl_fetch { | ||
|
||
# If you want to echo X-Geo-IP in the response too | ||
#set beresp.http.X-Geo-IP = req.http.X-Geo-IP; | ||
|
||
} | ||
|