angular i18n 应用程序的 Nginx HTTPS 重定向

Nginx HTTPS redirect for angular i18n application

我配置了 angular 本地化并使用了他们在文档中提供的 NGINX 示例。一切正常,但我遇到重定向问题。我的域正在使用 https,因此如果用户点击 https://www.example.com, nginx redirects to http://www.example.com/en

因此,重定向到正确的语言位置,但改用 HTTP。

server {
    listen 80;
    server_name localhost;
    root /www/data;

    # Fallback to default language if no preference defined by browser
    if ($accept_language ~ "^$") {
        set $accept_language "fr";
    }

    # Redirect "/" to Angular app in browser's preferred language
    rewrite ^/$ /$accept_language permanent;

    # Everything under the Angular app is always redirected to Angular in the correct language
    location ~ ^/(fr|de|en) {
        try_files $uri //index.html?$args;
    }
}

有什么方法可以在下面的代码中指定它应该重定向到 HTTPS 吗?

    # Everything under the Angular app is always redirected to Angular in the correct language
    location ~ ^/(fr|de|en) {
        try_files $uri //index.html?$args;
    }

如果有人遇到同样的问题,我使用

修复了
absolute_redirect off;

它将强制位置 header 使用相对 URL。

Location: /en