让您全面了解并上手亿速云产品
常见入门级使用教程
对外 API 开发文档中心
您历史提交的工单
您的每一条意见,我们都严谨处理
您的每一条建议,我们都认真对待
以PHP为例。
<?
print_r($_SERVER);
?>
以SpringBoot(Java)为例。
@RestController
public class TestController {
@GetMapping("/test")
public String test(HttpServletRequest request) {
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
String headerValue = request.getHeader(headerName);
System.out.println(headerName + ":" + headerValue);
}
return "success";
}
}
源服务器未使用代理转发该端口的请求(如没有使用nginx转发端口请求)。
http协议 请求的字段
array(10) {
["request_method"]=>
string(3) "GET"
["request_uri"]=>
string(1) "/"
["path_info"]=>
string(1) "/"
["request_time"]=>
int(1613802357)
["request_time_float"]=>
float(1613802357.2114)
["server_protocol"]=>
string(8) "HTTP/1.1"
["server_port"]=>
int(4501)
["remote_port"]=>
int(31205)
["remote_addr"]=>
string(14) "**购买的高防IP**"
["master_time"]=>
int(1613802357)
}
header中的 字段
array(11) {
["host"]=>
string(21) "添加的域名"
["x-real-ip"]=>
string(13) "真实的访客IP"
["x-forwarded-host"]=>
string(15) "访问域名"
["x-forwarded-scheme"]=>
string(4) "http"
["x-forwarded-for"]=>
string(13) "真实的访客IP"
["user-agent"]=>
string(115) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
["connection"]=>
string(10) "keep-alive"
["accept"]=>
string(50) "image/avif,image/webp,image/apng,image/*,*/*;q=0.8"
["referer"]=>
string(29) "..."
["accept-encoding"]=>
string(13) "gzip, deflate"
["accept-language"]=>
string(14) "zh-CN,zh;q=0.9"
}
源服务器使用代理服务转发端口的请求(如使用nginx转发)。
nginx 配置参考
server {
listen 8481;#如源机接收请求的端口设置为8481端口,而8481端口又转发请求
server_name localhost;
root /home/www/;
index index.php;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 100d;
}
location ~ .*\.(js|css)?$ {
expires 30d;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
返回字段参考
array
{
[USER] => www-data
[HOME] => /home/www-data
[HTTP_COOKIE] => yisu_sign_javascript=8bc2a608d434ebc5e6914faf090c4bda
[HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.9
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_REFERER] => ...
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_CACHE_CONTROL] => max-age=0
[HTTP_CONNECTION] => keep-alive
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
[HTTP_X_FORWARDED_FOR] => 真实访客的IP
[HTTP_X_FORWARDED_SCHEME] => http
[HTTP_X_FORWARDED_HOST] => 访问的域名
[HTTP_X_REAL_IP] => 真实访客IP
[HTTP_HOST] => 添加的域名
[REDIRECT_STATUS] => 200
[SERVER_NAME] => localhost
[SERVER_PORT] => 8481
[SERVER_ADDR] => 源服务器地址
[REMOTE_PORT] => 34338
[REMOTE_ADDR] => 购买的高防IP
[SERVER_SOFTWARE] => nginx/1.19.2
[GATEWAY_INTERFACE] => CGI/1.1
[REQUEST_SCHEME] => http
[SERVER_PROTOCOL] => HTTP/1.0
[DOCUMENT_ROOT] => /home/www
[DOCUMENT_URI] => /index.php
[REQUEST_URI] => /
[SCRIPT_NAME] => /index.php
[CONTENT_LENGTH] =>
[CONTENT_TYPE] =>
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[QY_DEBUG] => 1
[QY_CONF] => dev
[PATH_TRANSLATED] => /home/www
[PATH_INFO] =>
[SCRIPT_FILENAME] => /home/www/index.php
[FCGI_ROLE] => RESPONDER
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1613802985.2393
[REQUEST_TIME] => 1613802985
}
Array
{
[USER] => www-data
[HOME] => /home/www-data
[HTTP_COOKIE] => yisu_sign_javascript=8bc2a608d434ebc5e6914faf090c4bda
[HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.9
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_REFERER] => ...
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_CACHE_CONTROL] => max-age=0
[HTTP_CONNECTION] => keep-alive
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
[HTTP_X_FORWARDED_FOR] => 真实访客的IP
[HTTP_X_FORWARDED_SCHEME] => http
[HTTP_X_FORWARDED_HOST] => 访问的域名
[HTTP_X_REAL_IP] => 真实访客IP
[HTTP_HOST] => 是添加的域名,不是回源填写的域名
[REDIRECT_STATUS] => 200
[SERVER_NAME] => localhost
[SERVER_PORT] => 8481
[SERVER_ADDR] => 源服务器地址
[REMOTE_PORT] => 34338
[REMOTE_ADDR] => 购买的高防IP
[SERVER_SOFTWARE] => nginx/1.19.2
[GATEWAY_INTERFACE] => CGI/1.1
[REQUEST_SCHEME] => http
[SERVER_PROTOCOL] => HTTP/1.0
[DOCUMENT_ROOT] => /home/www
[DOCUMENT_URI] => /index.php
[REQUEST_URI] => /
[SCRIPT_NAME] => /index.php
[CONTENT_LENGTH] =>
[CONTENT_TYPE] =>
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[QY_DEBUG] => 1
[QY_CONF] => dev
[PATH_TRANSLATED] => /home/www
[PATH_INFO] =>
[SCRIPT_FILENAME] => /home/www/index.php
[FCGI_ROLE] => RESPONDER
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1613802985.2393
[REQUEST_TIME] => 1613802985
}