$_SERVER
变量包含[HTTP_X_REQUEST_ID] => 84708dd39a6c0c91e0d1a97404b40f75
代理服务器
配置
server {
...
add_header X-Request-ID $request_id;
proxy_set_header X-Request-ID $request_id;
location ~ ^/api/(.*) {
proxy_pass http://192.168.0.1:8080/$1$is_args$args;
}
...
}
日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_id"';
日志
172.17.0.1 ...... "84708dd39a6c0c91e0d1a97404b40f75"
上游服务器
配置
server {
location ~ ^/index\.php(/|$) {
fastcgi_pass php_server:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
}
日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_id"';
日志
172.20.0.1 ...... "172.17.0.1" "7376e0cead9741e7ec07a9194efc80e6"
预期日志
172.20.0.1 ...... "172.17.0.1" "84708dd39a6c0c91e0d1a97404b40f75"