Nginx的proxy_set_header不能用于Apache GEOIP

我正在使用Nginx的反向代理apache2使用以下教程 。

然后,我尝试使用本教程将geoip安装到Nginx

反向代理完美地工作了一段时间,直到我试图安装geoip数据库,所以我可以在PHP上获得国家代码。

我有以下的nginxconfiguration为教程指示。

location ~ \.php$ { # location / { #fastcgi_pass unix:/run/php/php7.0-fpm.sock; #include snippets/fastcgi-php.conf; proxy_pass http://1.2.3.4:8080$request_uri; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header GEOIP_COUNTRY_CODE $geoip_country_code; proxy_set_header GEOIP_COUNTRY_CODE3 $geoip_country_code3; proxy_set_header GEOIP_COUNTRY_NAME $geoip_country_name; proxy_set_header GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code; proxy_set_header GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3; proxy_set_header GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name; proxy_set_header GEOIP_REGION $geoip_region; proxy_set_header GEOIP_CITY $geoip_city; proxy_set_header GEOIP_POSTAL_CODE $geoip_postal_code; proxy_set_header GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code; proxy_set_header GEOIP_LATITUDE $geoip_latitude; proxy_set_header GEOIP_LONGITUDE $geoip_longitude; include /etc/nginx/proxy_params; } 

如果我使用proxy_pass到apache2,GEOIPvariables是**都不在phpinfo中显示

如果我直接使用nginx fastcgi_pass(closures反向代理到Apache)我可以得到设置的环境variables,它们反映在phpinfo中。

看起来,proxy_set_header可能不工作,因为Apache似乎没有阅读它。

我有什么要做,所以Apache可以得到所有的variables?

看来,本教程和其他多个网站,从这个geoip nginx教程复制代码是错误/过时的。

当设置代理标题时,似乎不能使用下划线(_)和使用( – )。 所以换了之后

 proxy_set_header GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code; 

对此

 proxy_set_header GEOIP-CITY-COUNTRY-CODE $geoip_city_country_code; 

Apache能够获取variables,现在也显示在我的phpinfo上。

我的PHP完整的位置块,现在看起来像这样。

 location ~ \.php$ { proxy_pass http://1.2.3.4:8080$request_uri; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header GEOIP-COUNTRY-CODE $geoip_country_code; proxy_set_header GEOIP-COUNTRY-CODE3 $geoip_country_code3; proxy_set_header GEOIP-COUNTRY-NAME $geoip_country_name; proxy_set_header GEOIP-CITY-COUNTRY-CODE $geoip_city_country_code; proxy_set_header GEOIP-CITY-COUNTRY-CODE3 $geoip_city_country_code3; proxy_set_header GEOIP-CITY-COUNTRY-NAME $geoip_city_country_name; proxy_set_header GEOIP-REGION $geoip_region; proxy_set_header GEOIP-CITY $geoip_city; proxy_set_header GEOIP-POSTAL_CODE $geoip_postal_code; proxy_set_header GEOIP-CITY-CONTINENT-CODE $geoip_city_continent_code; proxy_set_header GEOIP-LATITUDE $geoip_latitude; proxy_set_header GEOIP-LONGITUDE $geoip_longitude; include /etc/nginx/proxy_params; } 

用他上面的设置,我将能够得到以下服务器variables与他们的值填充。 请注意,出于安全原因,某些服务器添加了HTTP前缀。 不知何故……破折号再次转换为下划线。

 $_SERVER['HTTP_GEOIP_LONGITUDE'] $_SERVER['HTTP_GEOIP_LATITUDE'] $_SERVER['HTTP_GEOIP_CITY'] $_SERVER['HTTP_GEOIP_REGION'] $_SERVER['HTTP_GEOIP_CITY_COUNTRY_CODE'] $_SERVER['HTTP_GEOIP_COUNTRY_NAME'] $_SERVER['HTTP_GEOIP_COUNTRY_CODE3'] $_SERVER['HTTP_GEOIP_COUNTRY_CODE']