Nginx之设定Response Head -yellowcong

加这个response Head需要依赖于nginx得 headers-more-nginx-module 这个模块来增加返回得head信息,我们可以在请求得时候,增加requestid来增加整个链路得调用,有点类似于链路追踪了,可以看到请求得前后结果。

准备工作

Nginx之解压编译安装-yellowcong

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.csdn.net/cxm19881208/article/details/64441890

在这里插入图片描述

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

狂飙的yellowcong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值