We are wanting it so that when the website is accessed, we serve the appropriate index.html
for the language in the Accept-Language
request header. The problem is that our configuration does not seem to be working.
The configuration we have in NGINX (the two add_header lines are for debugging):
set $first_language $http_accept_language;
if ($http_accept_language ~* '^(.+?),') {
set $first_language $1;
}
set $language_suffix 'en';
if ($first_language ~* 'fr') {
set $language_suffix 'fr';
}
location / {
root /usr/share/nginx/html;
add_header x-eval-lang $language_suffix;
if (-f /index.$language_suffix.html) {
add_header x-xxx '33';
}
try_files $uri $uri/ /index.$language_suffix.html /index.html;
}
In the folder we have:
index.html
index.en.html
index.fr.html
The expected behaviour is to serve up index.en.html
or index.fr.html
as appropriate, but is instead serving up index.html
. We aren't getting the x-xxx
header added, suggesting I am not constructing the filename properly.
This is running in a Docker container.
So testing in a non-Dockerised NGINX server shows this should work, suggesting that it is not seeing the localised files for some reason.
NGINX version is 1.22.1