我的配置有问题,这就是我想要的工作方式 mydomain.com -> 重定向到正确的语言:mydomain.com/en/或 mydomain.com/fr/
我有两个带有 i18n 的 Angular 构建,每种语言一个。 语言重定向有效,但与 Angular 2 的直接链接无效: 如果我去 mydomain.com/fr/connect -> 404
这是我的nginx配置
map $http_accept_language $lang {
default en;
~*^fr fr;
}
server {
listen 80;
server_name domain.com www.domain.com;
root /usr/share/nginx/html;
index index.html index.htm;
location = / {
rewrite "^.$" /$lang/ break;
}
location = /$lang/ {
try_files $uri $uri/ /index.html;
}
}
如果你们中的一些人知道这一点,我只是被困在那里,我是一个 nginx 初学者 :/
最佳答案
第二个位置 block 是错误的。您可能需要将所有内容都定向到 index.html
(资源文件除外)。你可以尝试这样的事情:
map $http_accept_language $lang {
default en;
~*^fr fr;
}
server {
listen 80;
server_name domain.com www.domain.com;
root /usr/share/nginx/html;
index index.html index.htm;
location = / {
return 302 /$lang/;
}
location / {
try_files $uri $uri/ /index.html;
}
}
关于angular - 带 Angular 4 的 nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44843110/