在nginx中为捷克语选择不同的索引文件

ep6jt1vc  于 2023-06-28  发布在  Nginx
关注(0)|答案(1)|浏览(99)

我想使用一个不同的主页为游客使用捷克语。我发现了类似的问题(#1#2),我读了nginx手册,但我不能使它工作。它始终提供默认的index.html而不是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;
  }
}

测试用途:

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>

我在Debian上使用nginx。

kqlmhetl

kqlmhetl1#

我在nginx-users slack上寻求帮助,这是解决方案:

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

我还了解到,我可以看到Nginx如何通过调试日志级别处理我的请求。在Debian中你不需要额外的软件包,调试程序已经编译好了。

error_log /var/log/nginx/error.log debug;

相关问题