简体   繁体   English

如何调试请求标头?

[英]How to debug request headers?

Apache server running behind proxy server / load balancer. 在代理服务器/负载平衡器后面运行的Apache服务器。 I wan't to access client's IP address with X-Forwarded-For but I can't find it. 我无法使用X-Forwarded-For访问客户端的IP地址,但找不到。

I can confirm mod_remoteip loaded and configured. 我可以确认mod_remoteip已加载并配置。

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

PHP's $_SERVER global 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

My question is, how can I confirm proxy server doesn't forward client's ip address in request header? 我的问题是,如何确认代理服务器未在请求标头中转发客户的IP地址? Should it be in $_SERVER global? 应该在全局$ _SERVER中吗? If not, how can log all request headers including custom headers? 如果没有,如何记录包括自定义标头在内的所有请求标头?

In PHP you can get the request headers as an array by apache_request_headers() . 在PHP中,您可以通过apache_request_headers()将请求标头作为数组apache_request_headers()

There are rumours circulating, this function would not guarantee to return all headers. 有谣言流传,此函数不能保证返回所有标头。 I could not verify that yet by finding any missing header, however, I could imagine that malformed lines might not be considered as headers. 我无法通过找到任何缺少的标题来进行验证,但是,我可以想象格式错误的行可能不会被视为标题。

Unfortunately there is no way to access the full raw request in PHP. 不幸的是,没有办法在PHP中访问完整的原始请求。 You might want to do so using some CGI script language like Perl instead which provides access to the raw request. 您可能想使用某些CGI脚本语言(例如Perl)来实现,该语言提供对原始请求的访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM