【发布时间】:2021-01-12 17:54:09
【问题描述】:
我使用 Angular 9 构建了一个 i18n 应用程序。我的 api 使用 /api/ url 代理。但是由于我添加了 i18n,代理不再起作用。 Rq:(Angular 将 /fr/ 或 /en/ 添加到 url,因为我在编译时添加了 --baseHref 标志)
我想知道如何告诉我的代理将我的应用的动态 basehref 添加到代理 url 中? 示例:如何将 GET myapp.com/fr/api/jobs 转换为 GET myapp.com/api/jobs ?
所以我有这个 nginx 配置:
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;
}
我正在尝试在 /api/ 之前收听所有内容,但这不起作用...
【问题讨论】:
-
尝试添加
~进行正则表达式匹配:location ~ .*/api/ {..}。 -
好的,我现在就试试。所以添加
~.*/将监听 /api/ 之前的任何字符,然后仅使用 /api/ 重定向到 rest-api:9000 ? -
我不能在推荐中使用多行降价,所以我会放弃答案。
标签: angular nginx proxy internationalization reverse-proxy