nginx 设置每天生产一份日志

 

nginx 设置每天生产一份日志,

需要放进 service里面

     if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
                set $year $1;
                set $month $2;
                set $day $3;
         }

    access_log  logs/xxxx.access_$year-$month-$day.log ;

 

出现错误:

2019/04/17 17:02:54 [crit] 21394#0: *25 open() "/usr/nginx/logs/xxxx.access_2019-04-17.log" failed (13: Permission denied) while logging request, client:

解决:logs目录当前用户没有权限生成文件

 

以下是完整代码 ↓↓↓↓↓

upstream myLocalhost{
      server localhost:8080 weight=1;
}
	


    server {
        listen       80;
        listen       443 ssl;
        server_name  xxxxxxxx;

        #charset koi8-r;

		
		if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
				set $year $1;
				set $month $2;
				set $day $3;
		}
		access_log  
        logs/xxxxxx.access_$year-$month-$day.log ;
		error_log    logs/xxxxxx.error.log;

        location / {
           proxy_pass http://myLocalhost;
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto $scheme;
           proxy_connect_timeout       300;
           proxy_read_timeout          300;
           proxy_send_timeout          300;
           client_max_body_size    1000m;  
        }
		
        ssl_certificate      /xxxx.crt;
        ssl_certificate_key  /xxxx.key;

        ssl_session_timeout  5m;

        ssl_prefer_server_ciphers   on;

      
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        #location ~ /\.ht {
        #    deny  all;
        #}
    }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值