讓您全面了解并上手億速云產品
常見入門級使用教程
對外 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
}