【问题标题】:Nginx HTTPS redirect for angular i18n applicationAngular i18n 应用程序的 Nginx HTTPS 重定向
【发布时间】:2021-06-25 16:45:52
【问题描述】:

我配置了角度定位并使用了他们在文档中提供的 NGINX 示例。一切正常,但是我遇到了重定向问题。我的域使用的是https,所以如果用户点击https://www.example.com,nginx 会重定向到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 /$1/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 /$1/index.html?$args;
    }

【问题讨论】:

    标签: angular nginx https-redirect


    【解决方案1】:

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

    absolute_redirect off;
    

    它将强制 Location 标头使用相对 URL。

    Location: /en
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-28
      • 2016-05-10
      • 2015-05-09
      • 1970-01-01
      • 2017-05-15
      • 2016-05-18
      • 2020-09-11
      • 2018-08-21
      相关资源
      最近更新 更多