nginx 添加“$request_body“

1 vim /Data/apps/nginx/conf/nginx-app.conf

添加 ‘"$request_body"’

log_format main '$remote_addr - r e m o t e u s e r [ remote_user [ remoteuser[time_local] ’

    '"$request" $status $bytes_sent $request_time '

    '"$http_referer" "$http_user_agent" '

    '"$gzip_ratio"' '"$request_body"';

2 vim /Data/apps/nginx/conf/nginx-web.conf

添加 ‘"$request_body"’

log_format main '$http_x_forwarded_for r e m o t e u s e r [ remote_user [ remoteuser[time_local] ’

'"$request" $status $bytes_sent $request_time '

'"$http_referer" "$http_user_agent" '

'"$gzip_ratio" "$remote_addr" "$http_host"' '"$request_body"';

技术交流

CleverCode是一名架构师,技术交流,咨询问题,请加CleverCode创建的qq群(架构师俱乐部):517133582。加群和腾讯,阿里,百度,新浪等公司的架构师交流。【架构师俱乐部】宗旨:帮助你成长为架构师!
在这里插入图片描述

nginx中,$request和$request_method是两个不同的变量,分别表示客户端的HTTP请求和HTTP请求方法。 其中,$request包含了客户端发起的完整HTTP请求,包括请求方法、请求URI以及HTTP协议版本等信息。而$request_method则表示客户端发起的HTTP请求方法,如GET、POST等。 如果在nginx配置中,$request和$request_method的值不一致,通常是由于在配置文件中对这两个变量的使用不当导致的。比如,如果在一个location中使用了$request_method,而在另一个location中使用了$request,那么这两个变量的值就可能不一致。 举个例子,假设有如下的nginx配置: ``` location /api/ { if ($request_method = GET) { proxy_pass http://backend_server; } } location /api/post/ { proxy_pass http://backend_server; proxy_set_header Content-Type "application/x-www-form-urlencoded"; proxy_set_body $request; proxy_method POST; } ``` 上述配置中,第一个location使用了$request_method变量来判断请求方法是否为GET,如果是,则转发请求给backend_server。而第二个location则使用了$request变量来设置请求体,并将请求方法设置为POST。 如果客户端发送了一个POST请求到/api/,那么第一个location会被跳过,而第二个location会将请求体设置为客户端的完整HTTP请求,导致请求方法变为POST,从而与客户端实际发起的请求方法不一致。因此,建议在nginx配置中使用$request和$request_method时,要确保它们的使用方式和客户端实际发起的请求是一致的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值