0

I want to use a different home page for visitors using czech language. I found similar questions (#1, #2), I read nginx manual but I cannot make it work. It always serves a default index.html instead of index-cs.html.

map $http_accept_language $lang {
  default en;
  ~*cs.* cs;
  ~*cs-CZ.* cs;
  ~*^cs cs;
}

server {
  listen 80;
  server_name lelisoft.com www.lelisoft.com;
  root /var/www/lelisoft.com;
  index index.html;    
  location / {
    try_files $uri $uri/ /index-$lang.html /index.html;
  }
}

And the test usage:

curl -v -H "Accept-Language: cs" http://www.lelisoft.com 
*   Trying 162.55.54.132:80...
* Connected to www.lelisoft.com (162.55.54.132) port 80 (#0)
> GET / HTTP/1.1
> Host: www.lelisoft.com
> User-Agent: curl/8.0.1
> Accept: */*
> Accept-Language: cs
< Content-Length: 473
< Last-Modified: Sun, 25 Jun 2023 09:03:01 GMT
<
<!DOCTYPE html>
<html lang='eng'>
<head>

I am using nginx-full on Debian.

Leos Literak
  • 8,805
  • 19
  • 81
  • 156
  • `try_files $uri $uri/...` means it will try the requested URI first, then the directory `index.html`, *then* any `index-$lang.html` language option, right? So if you have an (en) `index.html`, it will be chosen before your `index-cs.html`. Most of the answers you already found deal with this by redirecting always, to the selected language. – Don't Panic Jun 26 '23 at 09:25
  • I dont think so. The option /index.html is the last one and /index-$lang.html is before it. – Leos Literak Jun 26 '23 at 18:29

1 Answers1

0

I asked for a help at nginx-users slack and this is the solution:

location / {
    index index-$lang.html index.html;
}

I have also learnt that I can see how Nginx processes my request with debug log level. You dont need extra package in Debian, the debug is compiled in.

error_log /var/log/nginx/error.log debug;
Leos Literak
  • 8,805
  • 19
  • 81
  • 156