I want to host the Angular i18n website using the Nginx proxy.
As per the official Nginx configuration suggestion https://angular.io/guide/i18n-common-deploy#nginx-example, my app.conf
file in the /etc/nginx/site-available
directory is like
map $http_accept_language $accept_language {
~*^de de;
~*^fr fr;
~*^en en;
}
server {
listen 80;
server_name i18n.example.io;
root /var/www/html/app/dist/app;
# Fallback to default language if no preference defined by browser
if ($accept_language ~ "^$") {
set $accept_language "en";
}
# Redirect "/" to Angular application in the preferred language of the browser
rewrite ^/$ /$accept_language permanent;
# Everything under the Angular application is always redirected to Angular in the
# correct language
location ~ ^/(fr|de|en) {
try_files $uri /$1/index.html?$args;
}
}
But when I try to access my website http://i18n.example.com
, it gives the following error in the error.log
file
2022/07/15 20:19:15 [error] 16886#16886: *1 rewrite or internal redirection cycle while internally redirecting to "/en/index.html", client: xx.xxx.235.xx, server: i18n.example.io, request: "GET /en HTTP/1.1", host: "i18n.example.io"