如何调试请求标头?

时间:2019-01-24 14:17:01

标签: php apache http-headers reverse-proxy mod-proxy

在代理服务器/负载均衡器后面运行的Apache服务器。我无法使用X-Forwarded-For访问客户端的IP地址,但是找不到。

我可以确认mod_remoteip已加载并配置。

[root~]# httpd -DDUMP_CONFIG | grep 'Forwarded'
RemoteIPHeader X-Forwarded-For
[root~]# httpd -M | grep remote
remoteip_module (shared)

PHP的 $ _ SERVER 全局

[USER] => apache
[HOME] => /usr/share/httpd
[FCGI_ROLE] => RESPONDER
[UNIQUE_ID] => XEmuZocZaMSZxKpDrFwvfgAAAAA
[HTTP_HOST] => domain.com
[HTTP_CONNECTION] => keep-alive
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 OPR/57.0.3098.116
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/.*;q=0.8
[HTTP_ACCEPT_ENCODING] => gzip, deflate, br
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.9
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
[SERVER_SIGNATURE] => 
[SERVER_SOFTWARE] => Apache
[SERVER_NAME] => domain.com
[SERVER_ADDR] => 192.168.98.25
[SERVER_PORT] => 80
[REMOTE_ADDR] => 192.168.99.148
[DOCUMENT_ROOT] => /var/www/html
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] => 
[CONTEXT_DOCUMENT_ROOT] => /var/www/html
[SERVER_ADMIN] => root@localhost
[SCRIPT_FILENAME] => /var/www/html/test.php
[REMOTE_PORT] => 11255
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => 
[REQUEST_URI] => /test.php
[SCRIPT_NAME] => /test.php
[PHP_SELF] => /test.php
[REQUEST_TIME_FLOAT] => 1548332646.3819
[REQUEST_TIME] => 1548332646

我的问题是,如何确定代理服务器未在请求标头中转发客户的IP地址?应该在全局$ _SERVER中吗?如果没有,如何记录包括自定义标头在内的所有请求标头?

1 个答案:

答案 0 :(得分:0)

在PHP中,您可以通过apache_request_headers()将请求标头作为数组获取。

有谣言流传,此函数不能保证返回 all 标头。我无法通过找到任何缺少的标题来进行验证,但是,我可以想象格式错误的行可能不会被视为标题。

不幸的是,无法使用PHP访问完整的原始请求。您可能希望使用某些CGI脚本语言(例如Perl)来实现此目的,该语言提供对原始请求的访问。