Load Balance for NGINX with WURFL InFuze

Load Balance for NGINX with WURFL InFuze

NGINX provides flexible software-based load balancing. And now with the WURFL InFuze for NGINX Plus module, you can quickly inject WURFL’s device intelligence into NGINX Plus’ load balancing logic.

NGINX Load Balancing Based on Smartphone, Tablet, or Other Device Form Factor

Load Balance with NGINX with WURFL InFuze
WURFL provides a number of options for load balancing criteria within Open Source NGINX or NGINX Plus.  We can envision load balancing by operating system, browser type, or the price of the smartphone. In our following example (which will work for both Open Source NGINX and NGINX Plus), we load balance based on the device’s form factor.


We separate traffic into three streams: Smartphone, Tablets, and Other (e.g. Desktop, Smart TV, etc.). NGINX can redirect those streams to specific servers.

#
# This is an example of how to configure Nginx to be used with WURFL Device Detection module.
#
# This configuration performs a redirection to different backends based on wurfl detection
# In this scenario we have three backend pools
# - One which serves SMARTPHONES devices (SmartphonePool - 192.168.140.2x)
# - One for TABLET devices (TabletPool - 192.168.140.3x)
# - One (GeneralPurposePool - 192.168.140.1x) for any other type of clients (desktop, smartTV,  etc ... )
#

worker_processes 1;

error_log logs/error.log info;
pid logs/nginx.pid;

events {
    worker_connections  512;
}


http {

    # the backends pool which serves requests coming from Smartphones
    upstream SmartphonePool {
        server 192.168.140.20;
        server 192.168.140.21;
        server 192.168.140.22;
    }

    # the backends pool which serves requests coming from Tablets
    upstream TabletPool {
        server 192.168.140.30;
        server 192.168.140.31;
        server 192.168.140.32;
    }

    # the backends pool which serves requests coming from any other client
    upstream GeneralPurposePool {
        server 192.168.140.10;
        server 192.168.140.11;
        server 192.168.140.12;
    }


    # -- Wurfl root definition, one per config. User MUST specify this path in order to make Wurfl engine correctly start.
    wurfl_root      /usr/share/wurfl/wurfl.zip;

    # Increase the variable hash size
    variables_hash_max_size 1024;
    variables_hash_bucket_size 1024;

    wurfl_cache_double_lru 10000,3000;

    # the WURFL virtual capability that tells if a device is a mobile phone
    wurfl_request_capability is_smartphone;
    wurfl_request_capability is_tablet;

    # Map to different upstream backends based on concatenation of is_smartphone and is_tablet (pipe separated)
    # $backend_pool_name contains the upstream name based on is_phone value

    map $wurfl_cap_is_smartphone|$wurfl_cap_is_tablet $backend_pool_name {
        true|false   "SmartphonePool";
        false|true   "TabletPool";
    # any other combination will redirect to GeneralPurposePool
        default      "GeneralPurposePool";
    }

    server {
        listen       80;
        server_name  localhost;

        location / {
            # here we redirect request to the target upstream
            proxy_pass http://$backend_pool_name;
        }
    }
}