【nginx可以有多个日志格式和可以同时输出多个日志文件吗? _Nginx 】 | IT修真院·坑乎
问题已收录 nginx可以有多个日志格式和可以同时输出多个日志文件吗?
我也踩过这个坑( 1 )
已统计您的踩坑,无需重复点击
回答(1)
Nginx
详细描述
编辑于2024-05-20
  • [北京|荣耀师兄]JAVA-岳晓鹏
    0

    亲自尝试,没有问题,我们正常写的时候,会将ngixn的配置文件中的main格式更改,我是直接在main格式下面添加了自己的user格式,输出位置没动原来的,在下面添加了自己的user的日志输出位置;详细代码如下;

           #日志文件输出格式 这个位置相于全局设置

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                          '$status $body_bytes_sent "$http_referer" '

                          '"$http_user_agent" "$http_x_forwarded_for"';

            log_format user '$remote_addr $request_time $upstream_response_time'

                            ' [$remote_user] [$time_local] [$request]'

                            ' [$status] [$body_bytes_sent] [$http_referer]'

                            ' [$http_x_forwarded_for] [$upstream_addr]';

    #' [$upstream_addr] [$upstream_status]';前面已经重复,这个addr可以显示端口信息,留着

            #请求日志保存位置

        #access_log  logs/access.log  main;

            access_log logs/user_access.log user;

            access_log logs/access.log main;


    编辑于2018-10-12