[英]Angular i18n nginx redirection
早上好,
我正在尝试部署我的 Angular 9 应用程序的本地化版本。 我已将其部署在英语(主要语言)和西班牙语(定位语言)上
它工作得很好,除非我尝试访问没有 /es 或 /en-US 的 URL 。
当我访问 https://example.com/es/login 时工作正常,但当我访问https://example.com/login时给我发回错误。 我尝试了所有可能的 nginx 配置,但没有任何运气。
我不知道这是否可能,或者我只是在浪费时间......
我的 nginx.config
server {
listen 443 ssl;
server_name https://example.com;
ssl_certificate /etc/nginx/certs/certificate.crt;
ssl_certificate_key /etc/nginx/certs/certificate.key;
ssl on;
root /usr/share/nginx/html;
index index.html index.htm;
location /en-US/ {
alias /usr/share/nginx/html/en-US/;
try_files $uri$args $uri$args/ /en-US/index.html;
}
location /es/ {
alias /usr/share/nginx/html/es/;
try_files $uri$args $uri$args/ /es/index.html;
}
set $first_language $http_accept_language;
if ($http_accept_language ~* '^(.+?),') {
set $first_language $1;
}
set $language_suffix 'en';
if ($first_language ~* 'es') {
set $language_suffix 'es';
}
location / {
rewrite ^/$ https://$host/$language_suffix$request_uri;
}
}
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://$host$request_uri;
}
提前致谢:)
我刚刚找到了解决方案,它对我有用:
只是改变
location / {
rewrite ^/$ https://$host/$language_suffix$request_uri;
}
至
location / {
rewrite ^/$ https://$host/$language_suffix$request_uri;
try_files $uri$args $uri$args/ /$language_suffix/index.html;
}
希望它对某人有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.