I have a situation where I need to serve all the requests from https://example.com/api/v1
from a different folder let's say /var/www/firstversion/public
and https://example.com/api/v2
from other folder /var/www/secondversion/public
Below is how my current configuration looks like
server {
root /var/www/firstversion/public/;
index index.html index.php index.htm index.nginx-debian.html;
server_name example.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /api/v2/ {
alias /var/www/secondversion/public/;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
The problem here is that I am getting response always from the /var/www/firstversion/public/
. However, to verify whether the location block is being selected I tried adding return 302 https://google.com
and it worked. So the location pattern is matching but somehow the alias/root
isn't working. Can someone point in the right direction or what am i missing?