您当前的位置:首页 > 计算机 > 服务器 > Nginx

nginx 设置每天生产一份日志

时间:08-26来源:作者:点击数:
城东书院 www.cdsy.xyz

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;
        #}
    }
城东书院 www.cdsy.xyz
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐