我配置了角度定位并使用了他们在文档中提供的 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;
}
答案 0 :(得分:0)
如果有人遇到同样的问题,我使用了
absolute_redirect off;
它将强制 Location 标头使用相对 URL。
Location: /en