zoukankan      html  css  js  c++  java
  • Nginx修改access.log日志时间格式

    摘自:https://www.cnblogs.com/bigberg/p/7774508.html

              https://yq.aliyun.com/articles/69512

    安装服务器:125.210.163.97
    所需安装软件目录:/opt/software

    nginx需要模块:
    http_stub_status_module
    http_ssl_module
    http_gzip_static_module
    http_mp4_module


    安装步骤:
    1、pcre:
    wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
    tar zxvf pcre-8.35.tar.gz
    cd pcre-8.35
    ./configure --prefix=/usr/local/src/pcre-8.35
    make && make install
    pcre-config --version

    2、zlib:
    wget http://zlib.net/zlib-1.2.11.tar.gz
    tar zxvf zlib-1.2.11.tar.gz
    cd zlib-1.2.11
    ./configure
    make && make install

    3、nginx
    wget http://nginx.org/download/nginx-1.14.0.tar.gz
    tar zxvf nginx-1.14.0.tar.gz
    cd nginx-1.14.0
    ./configure --prefix=/opt/nginx-1.14.0 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_mp4_module --with-zlib=../zlib-1.2.11 --with-pcre=../pcre-8.35/
    make && make install


    启动:
    /opt/nginx-1.14.0/sbin/nginx -c /opt/nginx-1.14.0/conf/nginx.conf


    测试播放地址:
    本地地址:http://125.210.163.97/mp4/hot/20180310/201803101700/20180310170000100000_QT.mp4
    回源地址:
    http://125.210.163.95/mp4/hot/20180801/201808010054/201808010054021002_IOS.mp4
    http://125.210.163.97/mp4/hot/20180801/201808010054/201808010054021002_IOS.mp4

    =================修改nginx的日期格式======================

    要求需要修改nginx日志中的时间格式20100823172711,而Nginx的默认日志时间格式为23/Aug/2010:17:26:44 +0800
    1.修改src/http/modules/ngx_http_log_module.c
    第一处
    修改前:
     { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1,
                              ngx_http_log_time },
    修改后:
    { ngx_string("time_local"), sizeof("19700928120000 +0600") - 1,
                              ngx_http_log_time },
    第二处
    修改前:
      return ngx_cpymem(buf, ngx_cached_http_log_time.data,
                          ngx_cached_http_log_time.len);
    修改后:
      return ngx_cpymem(buf, ngx_cached_err_log_time.data,
                          ngx_cached_err_log_time.len-5);

    2、修改 src/core/ngx_times.c 140行
    修改前
     (void) ngx_sprintf(p1, "%4d/%02d/%02d %02d:%02d:%02d",
                           tm.ngx_tm_year, tm.ngx_tm_mon,
                           tm.ngx_tm_mday, tm.ngx_tm_hour,
                           tm.ngx_tm_min, tm.ngx_tm_sec);
    修改后
        (void) ngx_sprintf(p1, "%4d%02d%02d%02d%02d%02d",
                           tm.ngx_tm_year, tm.ngx_tm_mon,
                           tm.ngx_tm_mday, tm.ngx_tm_hour,
                           tm.ngx_tm_min, tm.ngx_tm_sec);
    效果对比:
    修改前:
    1|10/Oct/2018:17:39:30 +0800|CACHE|17|58.100.228.244|59190|Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A456 Safari/602.1|125.210.163.97|80|HTTP|http://125.210.163.97:80/mp4/hot/20180310/201803101700/20180310170000100000_QT.mp4?-|10/Oct/2018:17:39:30 +0800|4.372|10/Oct/2018:17:39:30 +0800|10/Oct/2018:17:39:30 +0800|1|100|8722531|426|TCP|0|8722183|0|206
    修改后:
    1|20181011113506|CACHE|3|58.100.228.249|53656|VLC/2.2.4 LibVLC/2.2.4|125.210.163.97|80|HTTP|http://125.210.163.97:80/mp4/hot/20180310/201803101700/20180310170000100000_QT.mp4?-|20181011113506|0.056|20181011113506|20181011113506|1|100|153638|186|TCP|0|153300|0|206

    同时附带一下nginx的平滑升级


    好了,现在我们开始将Nginx平滑升级到稳定版V1.14.0。
    1、下载最新的Nginx源码安装包
    wget http://nginx.org/download/nginx-1.14.0.tar.gz

    2、配置并编译Nginx(不要执行make install步骤)
    # tar zxvf nginx-1.14.0.tar.gz

    # cd nginx-1.14.0
    #./configure --prefix=/opt/nginx-1.14.0 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_mp4_module --with-zlib=../zlib-1.2.11 --with-pcre=../pcre-8.35/

    # make
    (make编译下就OK,不要执行make install。)

    3、替换旧版本的Nginx
    #mv /opt/nginx-1.14.0/sbin/nginx /opt/nginx-1.14.0//sbin/nginx.old
    备份旧版本的nginx的二进制文件。

    # cd objs/
    在objs目录下可以看到刚刚编译好的新版本的nginx的二进制文件。

    # cp nginx /opt/nginx-1.14.0/sbin/
    复制新版本的nginx文件到你的nginx目录。

    # /opt/nginx-1.14.0/sbin/nginx -t
    测试新版本的nginx是否配置正常。如果提示:
    the configuration file /web/nginx/conf/nginx.conf syntax is ok
    configuration file /web/nginx/conf/nginx.conf test is successful
    则表示配置正确。

    # kill 旧的nginx进程
    killall nginx

    4、重启nginx服务
    /opt/nginx-1.14.0/sbin/nginx -c /opt/nginx-1.14.0/conf/nginx.conf

    # /opt/nginx-1.14.0/sbin/nginx -V
    获取Nginx版本信息,如果提示:
    nginx version: nginx/1.14.0
    则表示升级成功。

  • 相关阅读:
    iOS中文API之UITouch详解
    iOS中文API之UIResponder介绍
    NSProxy
    NSObject
    Objective-C 简介
    【摘录】在Windows平台上使用Objective-C
    基于VM10+Win7安装Mac OSX10.11 El Capitan
    关于安装黑苹果
    insta经典滤镜下载
    GPUImage简单滤镜使用之色阶(三)
  • 原文地址:https://www.cnblogs.com/shicf/p/9771813.html
Copyright © 2011-2022 走看看