I got the same error when I try to deploy angular UI in a subfolder of nginx.
Finally, I fixed it. Wish it helpful.
Let's say if you want to host your website https://www.yourdomain.com/sub1/
Step 1: use --base-href to build
ng build --base-href=/sub1/
Step 2: config in nginx
There are 2 ways to host your subfolder.
Assuming that your dist folder locates in html/sub1dist
1)Host local dist as subfolder
server {
listen 80;
server_name localhost;
location /sub1 {
alias html/sub1dist;
try_files $uri $uri/ /index.html =404;
}
}
2)Proxy pass another endpoint as subfolder
server {
listen 80;
server_name localhost;
location /sub1/ {
# rewrite to remove the subfolder
rewrite ^/sub1/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:8071;
}
}
server {
listen 8071;
server_name localhost;
location / {
root html/sub1dist;
try_files $uri $uri/ /index.html =404;
}
}
Each of above solutions works fine for me.