I have really simple nginx configuration with 3 locations inside. Each of them have it's own root directory + I should be able to add another in the future easily.
What I want:
Request /admin
=> location ^/admin(/|$)
Request /admin/
=> location ^/admin(/|$)
Request /admin/blabla
=> location ^/admin(/|$)
Request /client
=> location ^/client(/|$)
Request /client/
=> location ^/client(/|$)
Request /client/blabla
=> location ^/client(/|$)
Request /blabla
=> location /
Request /admin-blabla
=> location /
Request /client-blabla
=> location /
Actual result:
All requests goes to location /
.
I tried many different suggestions from docs, stackoverflow and other sources using different combinations of aliases, try_files, roots and regexes, but nothing worked for me.
Only when I tried to use just return 200 'admin';
and return 200 'front'
it worked as intended.
Minimal config:
server {
listen 80;
index index.html;
location / {
root /var/www/html/www_new/front;
try_files $uri $uri/ /index.html;
}
location ~ ^/admin(/|$) {
root /var/www/html/www_new/admin;
try_files $uri $uri/ /index.html;
}
location ~ ^/client(/|$) {
root /var/www/html/www_new/client;
try_files $uri $uri/ /index.html;
}
}
Directory structure:
- /admin
- /client
- /front
Thank you