Bala's Blog

JOY OF PROGRAMMING

Month: May, 2012

Varnish config for caching

Varnish is one of the powerful caching used widely.

The below config is the basic config for varnish

backend default {

.host = “127.0.0.1”;
.port = “8071”;
}

It should be added in the default.vcl in /etc/varnish/default.vcl

Then it should be restarted by using

sudo varnishd -f /etc/varnish/default.vcl start

The main advantage of varnish caching is , It is very powerful for serving dynamic content.

more config to follow/……………

Nginx Config for load balancing ( using UPStream module)

Upstream module in nginx gives the way for load balancing.

The below is the nginx config for load balancing two redis slaves

upstream app_cluster_1 {
server 127.0.0.1:6379;
server 127.0.0.1:6380;
}

server {
listen 0.0.0.0:8001;
server_name nodetest.local nodetest;
access_log /var/log/nginx/nodetest.log;
error_log /var/log/nginx/nodetesterrot.log;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;

proxy_pass http://app_cluster_1/;
proxy_redirect off;
}

}

HAProxy Config for Load balancing the servers

I tried using HAPRoxy for load balancing between the app servers as well as the database slaves.

The generic config for the HAPRoxy is

global
pidfile /tmp/haproxy-queue.pid

defaults
mode tcp
balance roundrobin
option httpclose
option forwardfor

listen redis 0.0.0.0:8011
server server5 127.0.0.1:6379 maxconn 1 check
server server6 127.0.0.1:6380 maxconn 1 check

 

For getting realtime statistics

the below config is used and the port can be used to get the statistics

listen stats :1936
mode http
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /