如何在Nginx访问日志中记录grpc状态?

时间:2020-08-25 11:37:15

标签: nginx grpc http2

我想在Nginx访问日志中记录grpc状态代码 尝试过

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $http_grpc_status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

但不起作用,Nginx将仅记录http状态代码,而不记录grpc_status

1 个答案:

答案 0 :(得分:1)

*是什么意思? GRPCS状态?

您已经尝试过了

  • 制作文件日志:

    • nano / var / log / nginx / [filelog] .log
  • [关闭并保存]

  • 在.conf

    中尝试

out服务器指令

log_format prog3'$ remote_addr-$ remote_user [$ time_local]“ $ request”'
'$ status $ body_bytes_sent“ $ http_referer”'
'“ $ http_user_agent” $ server_port $ scheme';

在服务器指令中

服务器{
.... access_log /var/log/nginx/[filelog].log prog3;

  • 然后在模式调试中执行nginx
    • 停止nginx
    • /etc/init.d/nginx停止
  • 运行nginx-debug
    • /etc/init.d/nginx-debug start