nginx 输出所有请求头
要输出所有请求头,可以在nginx配置文件中添加如下代码:
server {
listen 80;
server_name example.com;
location / {
add_header Content-Type text/plain;
add_header X-My-Header $http_user_agent;
return 200 "$http_host\n$http_user_agent\n$request_uri\n$http_referer\n";
}
}
在这个例子中,我们使用add_header指令添加了两个自定义的响应头,分别是Content-Type和X-My-Header。然后,我们在return指令中使用了Nginx的内置变量输出了所有请求头,包括Host、User-Agent、Referer等。
请注意,为了避免输出过多的信息造成信息泄漏,通常不建议将所有请求头都输出。如果需要调试或排查问题,建议只输出关键的请求头。
原文地址: https://www.cveoy.top/t/topic/cvJN 著作权归作者所有。请勿转载和采集!