Nginx之设定Response Head -yellowcong
加这个response Head需要依赖于nginx得 headers-more-nginx-module 这个模块来增加返回得head信息,我们可以在请求得时候,增加requestid来增加整个链路得调用,有点类似于链路追踪了,可以看到请求得前后结果。
准备工作
nginx
#下载nginx headers 得模块
git clone https://github.com/openresty/headers-more-nginx-module.git
#进入nginx 配置nginx
cd nginx-1.14.0
#配置nginx
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module --add-module=/data/nginx/headers-more-nginx-module
#如果是nginx升级增加,不是全新安装,就不需要这种 make && make install 了,只需要 make 一下即可。
#编译执行
make && make install
重启nginx
#停止nginx服务
nginx -s stop
#启动服务
nginx
配置nginx
upstream tomcat_8080 {
server 192.168.112.2:8080;
}
server {
listen 80;
server_name test.yellowong.net;
index index.html index.htm index.php default.html default.htm default.php;
root /data/jeeroot/test.yellowong.net/ROOT;
location / {
proxy_pass http://tomcat_8080;
proxy_set_header X-Request-Id $request_id;
proxy_set_header Host $host;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
more_set_headers "X-Request-Id:$request_id";
more_set_headers "Server:yellowcong.com";
#more_clear_headers "Server: ";
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
}
location ~ ^/(WEB-INF)/ {
deny all;
}
location /logs/ {
deny all;
}
access_log /home/wwwlogs/test.yellowong.net.log access;
}
可以看到我们已经有X-Request-Id 这个参数返回了,可以美滋滋得监控前后台得数据了。
参考文章
http://www.ttlsa.com/nginx/nginx-custom-header-to-return-information-module-ngx_headers_more/
https://blog.****.net/cxm19881208/article/details/64441890