I am using nginx to proxy HTTP requests to a PHP application running in the scope of Apache 2.4 (mod_php5) within a Docker container (cbeer/piwik).
+------------------------------+
| Docker Container |
+-------+ | +--------+ +-----+ |
| nginx |----------->|->| apache |--------->| php | |
+-------+ proxy_pass | +--------+ mod_php5 +-----+ |
+------------------------------+
The PHP application is Piwik 2.16.
I inject GeoIP HTTP headers with nginx:
proxy_set_header GeoIP-Addr "$remote_addr";
proxy_set_header GeoIP-Country-Code "$geoip_country_code";
proxy_set_header GeoIP-Country-Name "$geoip_country_name";
proxy_set_header GeoIP-Continent-Code "$geoip_city_continent_code";
proxy_set_header GeoIP-Region-Name "$geoip_region_name";
proxy_set_header GeoIP-Region "$geoip_region";
proxy_set_header GeoIP-City "$geoip_city";
proxy_set_header GeoIP-Metro-Code "$geoip_dma_code";
proxy_set_header GeoIP-Area-Code "$geoip_area_code";
proxy_set_header GeoIP-Latitude "$geoip_latitude";
proxy_set_header GeoIP-Longitude "$geoip_longitude";
proxy_set_header GeoIP-Postal-Code "$geoip_postal_code";
proxy_set_header GeoIP-Isp "$geoip_org";
proxy_set_header GeoIP-Organization "$geoip_org";
proxy_set_header GeoIP-Netspeed "";
Unfortunately Piwik (at least thinks it) cannot see the via nginx injected request HTTP headers. On the Piwik settings page for geolocationing is a warning about Piwik could not find GeoIP variables within PHP's $_SERVER
. The GeoIP headers arrive as e.g. HTTP_GEOIP_ADDR
but have to be GEOIP_ADDR
. I also cannot edit the application to get use of these "new" header names.
@RichardSmith mentioned that I have to map HTTP_GEOIP_
variables to GEOIP_
within Apache using setenv. I tried several combinations but I did not get managed to use variables (request headers) as values for the environment variable.
SetEnv GEOIP_ADDR "%{HTTP_GEOIP_ADDR}e"
This results into the actual string "%{HTTP_GEOIP_CITY}e
" stored in the variable instead of the value of HTTP_GEOIP_CITY
.
How to map HTTP_GEOIP_
variables to GEOIP_
within Apache using setenv?
Your assumption on Apache's
SetEnv
directive syntax is wrong.From the documentation, it seems it's the other way around:
SetEnv HTTP_GEOIP_ADDR %{GeoIP-Addr}e
Here is the link for the documentation:
https://httpd.apache.org/docs/2.4/mod/mod_env.html#setenv
It states that
Sets an internal environment variable, which is then available to Apache HTTP Server modules, and passed on to CGI scripts and SSI pages.
So, if you swap your declaration, might work.