I was wondering how to serve an angular app based on the url while using nginx. So let's say there is a url called xyz.com/something/ and whenever there's something in the url, I want ngnix to route to an angular app. How do we acheive it, I saw similar questions here on SO like this but just couldn't get it working.
location /something/ {
root /var/www/xyz.com/html/something/;
try_files $uri $uri/ /index.html =404;
}
let's say normally the app would respond to urls like,
xyz.com/something/login
The below code is working fine though.
location / {
alias /var/www/xyz.com/html/something/;
try_files $uri $uri/ /index.html =404;
}
Have tried something with base-href too as described here and yet failed to get it working.
Tried the first answer as well.
Nginx CONFIG file:
location /admin {
root /var/www/xyz.com/html/;
try_files $uri $uri/ /admin/index.html;
}
location / {
alias /var/www/xyz.com/html/user/;
try_files $uri $uri/ /index.html =404;
}
Here /admin & /user refers to two different AngularJs projects present on same domain.
TEST CASES:
URL : www.xyz.com/admin/
RESPONSE : Blank page..
accessing index.html but not redirecting properly
URL : www.xyz.com/admin/login
RESPONSE : Blank page..
ERRORS : Cannot match any routes. URL Segment: 'login'
but I have routed properly..
Any Suggestions??