Nginx reverse proxy with dynamic basehref?
I have built an i18n app with Angular 9. My api is proxied with the /api/ url. But since i added i18n, proxy doesnt work anymore.
Rq: (Angular add /fr/ or /en/ to the url because i add –baseHref flag on compilation)
I want to know how can i tell to my proxy to add the dynamic basehref of my app to the proxy url ?
Exemple : How to transform GET myapp.com/fr/api/jobs to GET myapp.com/api/jobs ?
So i have this nginx configuration :
location /fr/ {
autoindex on;
try_files $uri$args $uri$args/ /fr/index.html;
}
location /en/ {
autoindex on;
try_files $uri$args $uri$args/ /en/index.html;
}
# Default to FR
location / {
# Autoindex is disabled here + the $uri$args/ is missing from try_files
try_files $uri$args /fr/index.html;
}
# Proxy to API call
location */api/ {
proxy_pass http://rest-api:9000;
}
I’m trying to listen everythin before /api/ but this doesnt work…
Source: Angular Questions
location */api/ {
proxy_pass http://rest-api:9000/api/;
}
should work