Nginx

Setting up Traffic Splitting with Nginx

Dependencies

Most default installations of NGINX will have ngx_http_proxy_module already installed and running. To check for this you can run a simple command:

terminal
$ nginx -V 2>&1 | tr ' ' '\n' | grep 'ngx_http_proxy_module'

Provided you have got the expected output then you are ready to continue to “Create a rewrite rule” without any further intervention.

Proxy Module Missing

If the output from the above Nginx query is different from the above, then we can access the nginx.conf file typically located in /etc/nginx/ to validate that the module is loaded, and if not, add it in.

terminal
$ sudo nano /etc/nginx/nginx.conf

Insert at the top of the file:

/etc/nginx/nginx.conf
load_module "modules/ngx_http_proxy_module.so";

You can now test your configuration file for syntax errors:

terminal
$ sudo nginx -t

With no problems reported, restart Nginx to apply your changes:

terminal
$ sudo systemctl restart nginx

Create a rule

Insert the following into the configuration file for your domain.

Make sure to replace GLOPAL_HOSTNAME placeholder with the value you receive from Glopal (for example store-1234.app.glopalstore.com) and that PATTERN is a regular expression describing list of in-scope paths you want to delegate to Glopal:

You can now test your configuration file for syntax errors:

terminal
$ sudo nginx -t

With no problems reported, restart Nginx to apply your changes:

terminal
$ sudo systemctl restart nginx

Testing your rule

To ensure the rule works as expected, conduct a series of tests by visiting URLs that should be affected by the rule and confirming that they are rewritten correctly.

That's it! You have now created a URL rewrite rule in Nginx.

Last updated