何修复nginx的configuration文件,以便能够服务于不同的语言?
我使用泊坞窗来服务我的angular度应用程序,这也是使用国际化的function几种语言。
使用以下命令将docker run -d -p 9090:80 -v "$(pwd)/dist:/usr/share/nginx/html" -v "$(pwd)/app.conf:/etc/nginx/conf.d/default.conf" nginx:alpine
指向dist
文件夹: docker run -d -p 9090:80 -v "$(pwd)/dist:/usr/share/nginx/html" -v "$(pwd)/app.conf:/etc/nginx/conf.d/default.conf" nginx:alpine
正如你可以在命令行中看到的那样,我还将try_files指令保存在app根目录中作为app.conf
,以便在重新加载页面/应用程序或直接针对特定的路由/上下文时避免出现404 NGINX错误 。
server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html index.htm; location / { try_files $uri /index.html; } }
一切正常,我可以达到: localhost:9090/home
除非当我尝试导航到一个特定的语言,如localhost:9090/es/
或localhost:9090/en/
然后我得到的错误:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'en' Error: Cannot match any routes. URL Segment: 'en'
文件夹: /es
和/en
是在dist
文件夹下生成的,脚本保存在package.json
:
"build-i18n": "for lang in en de; do ng build --output-path=dist/$lang --aot -prod --i18n-file=src/i18n/messages.$lang.xlf --i18n-format=xlf --locale=$lang; done"
并包含所有需要的bunlde文件来运行和呈现应用程序。
正常和预期的行为是,当我用特定的语言,如localhost:9090/en/
调用应用程序,该应用程序应该在englisch例如: localhost:9090/en_US/home
和如果我打电话localhost:9090/es/
,该应用程序应该在spanisch服务,例如localhost:9090/es_ES/home
导致我使用@angular/core
的LOCALE_ID
模块
在我在根应用程序下面添加了try_files指令之前,情况就是如此。它能够很好地达到所有不同的语言。
那么,我有什么改变和/或在add.conf
文件,以避免前面提到的错误?