Answer the question
In order to leave comments, you need to log in
Nginx: different root depending on cookies, partially working, problem with PHP - how to fix?
There is such a code, in both directories (root1 and root2) there are identical 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;
}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
}
Answer the question
In order to leave comments, you need to log in
In general, the root can only be set once. Try something like this, I checked, it seems to work.
server {
index index.html index.htm index.php;
server_name test.loc;
location / {
try_files $uri $uri/ /index.php?$args;
}
#error_page 500 502 503 504 /50x.html;
location ~ \.php$ {
if ($cookie_VAR = "1") {
root /Users/evgenij/projects/www/1;
}
if ($cookie_VAR = "2") {
root /Users/evgenij/projects/www/2;
}
root /Users/evgenij/projects/www/3;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
}
curl --cookie "VAR=1" http://test.loc
curl --cookie "VAR=2" http://test.loc
curl http://test.loc
Why do you need 2 identical applications depending on the cookie to run?
In fact, they will be slightly different, but at the moment for the purposes of testing the functionality, they are the same.
You need to make sure that everything works identically.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question