使用Nginx在Cloudflare上按国家重定向访客

时间:2018-07-23 20:41:23

标签: php apache nginx webserver nginx-location

我打算使用nginx代替apache,所以我想将此apache规则转换为nginx。

重新启动Nginx服务时出现以下错误

“ / etc / nginx / sites-enabled / default中的无效参数“ COUNTRY = $ 1””

原始Apache规则

    SetEnvIf CF-IPCountry "(.*)" COUNTRY=$1 
    <IfModule mod_rewrite.c> 
        RewriteEngine on 
        RewriteCond %{HTTP:X-Forwarded-Proto} =https 
        RewriteCond %{ENV:COUNTRY} [A-Z]{2} 
        RewriteCond %{QUERY_STRING} !country [NC] 
        RewriteRule ^/sumthing(.*) %{HTTP:X-Forwarded-Proto}://%{HTTP_HOST}%{REQUEST_URI}?country=%{ENV:COUNTRY} [L,QSA,R] 
    </IfModule>   

nginx规则

fastcgi_param   CF-IPCountry  "(.*)" COUNTRY=$1 ;
location / {
  if ($query_string !~ "country"){
    rewrite ^/consultation(.*) /%{HTTP:X-Forwarded-Proto}://$http_host$request_uri?country=$env_country redirect;
  }
}

任何人都可以告诉我问题出在哪里

0 个答案:

没有答案
相关问题