I'm serving multiple angular
apps from the same server
block in Nginx
. So in order to let the user browse directly to certain custom Angular
routes I've declared without having to go through the home page (and avoid the 404 page), I'm forwarding these routes from nginx to each angular app's index.html
, I've added a try_files
to each location
:
server {
listen 80;
server_name website.com;
# project1
location / {
alias /home/hakim/project1/dist/;
try_files $uri /index.html;
}
# project2
location /project2/ {
alias /home/hakim/project2/dist/;
try_files $uri /index.html;
}
# project3
location /project3/ {
alias /home/hakim/project3/dist/;
try_files $uri /index.html;
}
}
This solution avoids the 404 error when going to an Angular route, but the problem is that when I browse to /project2/
or /project3/
it redirects to the /project1/
. That's obviously not what is expected, since I want to have each location to forward to the /project-i/index.html
of the adequate project.