Changing Root Path in Nginx based on Cookie

If you want to change the root path of a domain in the Nginx web server based on a cookie then you can put the following lines of code in the sites conf file, ie the file within sites-available folder in /etc/nginx/ directory.

The MAP directives allow us to set the $rootpath variable based on conditions specified below. This $rootpath is then used to set the path in server directive.
This technique allows us to test files level changes on a production website with an existing database.
 

Updated on Dec 14, 2017