Load Balancing for NGINX Plus with WURFL InFuze
A version of this blog post originally appeared on the Scientia Mobile blog.
In April 2017, NGINX, Inc launched the NGINX Plus Certified Module Partner program, a program which allows third-party partners to build, deliver, and fully support modules for the NGINX Plus platform. NGINX Plus Certified Modules are fully supported by both NGINX, Inc., and by the module developers, and they open up additional features and application delivery management use cases for NGINX Plus customers.
WURFL InFuze is a great example of extending application delivery management to dynamically support responsive web design for multiple device types. Below is a guest blog post from Ken Jones of ScientiaMobile about their new WURFL NGINX Plus Certified Module.
An earlier version of this blog post originally appeared on the Scientia site in May. – Editor
NGINX provides flexible software-based high-availability load balancing and an application delivery platform. And now with the WURFL InFuze for NGINX Plus Certified Module, you can quickly inject WURFL’s device intelligence into NGINX Plus’ application delivery logic.
NGINX Load Balancing Based on Smartphone, Tablet, or Other Device Form Factor
WURFL provides a number of options for load balancing criteria within open source NGINX or NGINX Plus. We can implement 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.
To begin testing this scenario, you will need to edit the default NGINX configuration file, typically located at /etc/nginx/nginx.conf.
We separate traffic into three streams: smartphone, tablets, and other (such as 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 ... )
#
# -- Uncomment this if you are using NGINX Plus
# -- or you compiled WURFL module with --add-dynamic-module (WURFL API version 1.8.1.0 or above / NGINX OSS 1.9.11 or above).
#load_module modules/ngx_http_wurfl_module.so;
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;
}
}
}
Please note that the above example assumes sample IP addresses and upstream block names. You will need to edit accordingly for your test environment.
The post Load Balancing for NGINX Plus with WURFL InFuze appeared first on NGINX.
Leave a Reply