Published on 12/14/2017
Published by amit
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
map $http_cookie $rootpath { "~*revert_in" "/var/www/path to/htdocs"; default "/var/www/original/htdocs"; } server { server_name test1.loantap.in www.test1.loantap.in; ... ... ... root $rootpath; ... ... ... } |
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.