nginx geotargeting和proxpass

我有一个与我的Nginxconfiguration原型有点问题

情景如下:网站访问者将访问example.com。 Nginx使用GeoIP读取当前位置,并从浏览器接受语言头文件。

这个信息一定是指代理通行证

我的问题是,如何告诉Nginx使用这两个variables的代理通行证。 有了这个configuration,我变成了404错误。

任何想法?

geoip_country /usr/share/GeoIP/GeoIP.dat; geoip_proxy 10.241.16.0/24; upstream hybrisqa { server qa-hybris.local:9001; } server { listen 80 default_server; listen [::]:80 default_server; # root /var/www/html; allow all; access_log /var/log/nginx/test_access.log; error_log /var/log/nginx/test.error.log; # Add index.php to the list if you are using PHP # index index.html index.htm index.nginx-debian.html; server_name _; # return 301 /$geoip_country_code; location = / { rewrite_by_lua ' if (ngx.var.http_accept_language == nil or ngx.var.http_accept_language == "") then ngx.redirect("/en-" .. ngx.var.geoip_country_code .. "/") end for lang in (ngx.var.http_accept_language .. ","):gmatch("([^,]*),") do if string.sub(lang, 0, 2) == "en" then ngx.redirect("/en-" .. ngx.var.geoip_country_code .. "/" ) end if string.sub(lang, 0, 2) == "de" then ngx.redirect("/de-" .. ngx.var.geoip_country_code .. "/" ) end if string.sub(lang, 0, 2) == "nl" then ngx.redirect("/nl-" .. ngx.var.geoip_country_code .. "/" ) end end ngx.redirect("/en-US/") '; } location / { proxy_pass http://hybrisqa; try_files $uri $uri/ =404; } } 

Lua对此太复杂了。 使用map最简单。

请注意,地图的一个鲜为人知的特性是,他们可以通过连接来一次检查多个variables。

例如:

 map $geoip_country_code$http_accept_language $locale { default en-US ~^DEde de-DE ~^NLnl nl-NL # ... continue for every supported combination of language and country } server { location = / { return 302 /$locale/; } # ....