AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 761261
Accepted
burnersk
burnersk
Asked: 2016-03-04 02:06:43 +0800 CST2016-03-04 02:06:43 +0800 CST 2016-03-04 02:06:43 +0800 CST

如何使用 Apache 将 GeoIP HTTP 请求标头传递到后端?

  • 772

我正在使用 nginx 将 HTTP 请求代理到在 Docker 容器 ( cbeer/piwik ) 内运行在 Apache 2.4 (mod_php5) 范围内的 PHP 应用程序。

                     +------------------------------+
                     |        Docker Container      |
+-------+            |  +--------+          +-----+ |
| nginx |----------->|->| apache |--------->| php | |
+-------+ proxy_pass |  +--------+ mod_php5 +-----+ |
                     +------------------------------+

PHP 应用程序是 Piwik 2.16。

我用 nginx 注入 GeoIP HTTP 标头:

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         "";

不幸的是,Piwik(至少认为它)看不到通过 nginx 注入的请求 HTTP 标头。在用于地理定位的 Piwik 设置页面上是关于 Piwik 无法在 PHP 中找到 GeoIP 变量的警告$_SERVER。GeoIP 标头以 eg 形式到达,HTTP_GEOIP_ADDR但必须是GEOIP_ADDR. 我也无法编辑应用程序以使用这些“新”标题名称。

@RichardSmith 提到我必须使用 setenv将HTTP_GEOIP_变量映射到Apache 中。GEOIP_我尝试了几种组合,但没有设法使用变量(请求标头)作为环境变量的值。

SetEnv GEOIP_ADDR "%{HTTP_GEOIP_ADDR}e"

这导致%{HTTP_GEOIP_CITY}e存储在变量中的实际字符串“”而不是 的值HTTP_GEOIP_CITY。

如何使用 setenv 将HTTP_GEOIP_变量映射到GEOIP_Apache 中?

nginx
  • 1 1 个回答
  • 3461 Views

1 个回答

  • Voted
  1. Best Answer
    Marcel
    2016-07-12T02:16:27+08:002016-07-12T02:16:27+08:00

    您对 ApacheSetEnv指令语法的假设是错误的。

    从文档来看,似乎是相反的:

    SetEnv HTTP_GEOIP_ADDR %{GeoIP-Addr}e

    这是文档的链接:

    https://httpd.apache.org/docs/2.4/mod/mod_env.html#setenv

    它指出Sets an internal environment variable, which is then available to Apache HTTP Server modules, and passed on to CGI scripts and SSI pages.

    Example
    
    SetEnv SPECIAL_PATH /foo/bin
    

    所以,如果你交换你的声明,可能会奏效。

    • 2

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve