I'm trying to get an angular container running behind an AWS load balancer.
The load balancer serves other apps based on routes eg. elb.amazonaws.com/some-path
I started with this nginx.conf which works when accessing the container directly, but not behind the LB due to the /some-path that's also passed to the app.
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
}
}
I tried updated location / to location /some-path/
The first request to the app returns index.html correctly, but the subsequent calls fail as the base path disappears and is hitting nothing on the LB e.g.
RequestUrl: elb.amazonaws.com/runtime.js instead of elb.amazonaws.com/some-path/runtime.js
I noted below on the request headers it has the Referer correctly
Referer: elb.amazonaws.com/some-path/
I've tried to add different combinations of /some-path/ in location and try_files, and some other config in the app, but to no avail.
The only way I managed to get this working was to copy the app into a sub directory /usr/share/nginx/html/some-path and set that in try_files
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri$args $uri$args/ $uri $uri/ /some-path/index.html =404;
}
Then add it to index.html <base href="/some-path/">
Is there another way to handle this,(e.g. .net apis fix this with app.UsePathBase) without having to move the app to a subdirectory dictated by it's LB path?
Many thanks.