Answer the question
In order to leave comments, you need to log in
How to change nginx root directory depending on cookies?
Good afternoon, it is necessary to replace the root directory for root requests depending on cookies. Something like
root /path/to/rails/app/public;
if ($http_cookie ~* "dev_access") {
root /path/to/rails/app2/public;
}
Answer the question
In order to leave comments, you need to log in
Reading the documentation :
syntax: root path;
default: roothtml;
context: http, server, location, if in location
That's how it works.root /var/www/default; location / { if ($http_cookie ~ 'test') { root /var/www/test; } try_files $uri $uri/ /index.html; }
There is such a code, in both directories the same copies of the site (Yii)
server {
root /root1;
index index.html index.htm index.php;
server_name domain.ru;
location / {
if ($cookie_VAR = "1") {
root /root2;
}
try_files $uri $uri/ /index.php?$args;
}
#error_page 500 502 503 504 /50x.html;
location ~ \.php$ {
if ($cookie_VAR = "1") {
root /root2;
}
*********
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question