Documentation / Tutorials / Server
Changing Root Path in Nginx based on Cookie
/ Server / 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.
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.