'Cannot get SPA deep link to work with subdirectory redirect
I am trying to set up a straight-forward scenario. We have a SPA (Angular) app that is built into a subfolder of our nginx container (e.g. /usr/share/nginx/html/foo). When navigating to https://example.com, I want to be redirected to https://example.com/foo. I tried the following config:
user nginx;
worker_processes 1;
events { worker_connections 1024; }
http {
server {
listen 80;
root /usr/share/nginx/html;
include /etc/nginx/mime.types;
index index.html index.htm;
location = / {
rewrite "^$" /foo;
# return 301 ...
}
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
}
}
I have tried alternatives for the second location section, e.g.:
location ~ ^/ui(.*) {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
Redirect works, so https://example.com or https://example.com/foo works. But any deep link will not, e.g. https://example.com/foo/bar/baz. This will return 404 as it's likely not activating Angular.
As a side note, but perhaps important: this is hosted as a container within kubernetes, so I hope it's not the ingress that is blocking here.
With which configuration can I get the deep link to work as expected?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
