Today I want to try to install Varnish on FreeBSD. A few scenarios on my mind. Install varnish with nginx, lighttpd or cherokee with different port under Apache as front end. Due to lack of experience with Varnish I’ll start with Varnish using Apache first. Others will follow 🙂
Lets get started
Check Apache installation
# pkg_info | grep apache
apache22-2.2.26 Version 2.2.x of Apache web server with prefork MPM.
Check location of varnish
# whereis varnish
varnish: /usr/ports/www/varnish
Install varnish
# cd /usr/ports/www/varnish && make install
……….
===> SECURITY REPORT:
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/sbin/varnishd
/usr/local/bin/varnishtest
This port has installed the following startup scripts which may cause
these network services to be started at boot time.
/usr/local/etc/rc.d/varnishncsa
/usr/local/etc/rc.d/varnishd
/usr/local/etc/rc.d/varnishlog
If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type ‘make deinstall’
to deinstall the port if this is a concern.
For more information, and contact details about the security
status of this software, see the following webpage:
http://www.varnish-cache.org/
Great.
Check it
# pkg_info | grep varnish
varnish-3.0.4 The Varnish high-performance HTTP accelerator
Configure Varnish
Add varnish on rc.conf
# echo 'varnishd_enable=YES' >> /etc/rc.conf
Starting Varnish
# /usr/local/etc/rc.d/varnishd start
Starting varnishd.
Classic hash: 16383 buckets
Check if varnish really run?
# /usr/local/etc/rc.d/varnishd status
varnishd is not running.
Ok…ok..ok.
View varnish configuration
# ee /usr/local/etc/varnish/default.vcl
Inside the file I see these :
# Default backend definition. Set this to point to your content
# server.
#
# backend default {
# .host = “127.0.0.1”;
# .port = “8080”;
# }
It means the content need to run on port 8080.
Remove all # mark to be like this :
backend default {
.host = “127.0.0.1”;
.port = “8080”;
}
save the file.
Change apache configuration to run on port 8080.
# ee /usr/local/etc/apache22/httpd.conf
change
Listen 80
to
Listen 8080
save the fle.
Restart apache
# /usr/local/etc/rc.d/apache22 restart
Performing sanity check on apache22 configuration:
Syntax OK
Stopping apache22.
Waiting for PIDS: 770.
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache22.
# ps -ax | grep httpd
944 ?? Ss 0:00.11 /usr/local/sbin/httpd -DNOHTTPACCEPT
945 ?? S 0:00.00 /usr/local/sbin/httpd -DNOHTTPACCEPT
946 ?? I 0:00.00 /usr/local/sbin/httpd -DNOHTTPACCEPT
947 ?? I 0:00.00 /usr/local/sbin/httpd -DNOHTTPACCEPT
948 ?? I 0:00.00 /usr/local/sbin/httpd -DNOHTTPACCEPT
949 ?? I 0:00.00 /usr/local/sbin/httpd -DNOHTTPACCEPT
Retry to run varnish
# /usr/local/etc/rc.d/varnishd start
Starting varnishd.
Classic hash: 16383 buckets
Check varnish
# ps -ax | grep varnish
963 ?? Ss 0:00.00 varnishd: Varnish-Mgr freebsd92.rasyid.net (varnishd)
964 ?? S 0:00.03 varnishd: Varnish-Chld freebsd92.rasyid.net (varnishd)
966 0 R+ 0:00.00 grep varnish
Check Varnish
Check via phpinfo file, I can see it run on Varnish :
Interesting. I’ll continue this experiment with different web server as soon as possible.
See you.
P.S : you can enable varnish log
# echo 'varnishlog_enable=YES' >> /etc/rc.conf
# /usr/local/etc/rc.d/varnishlog start
Starting varnishlog.