3

I'm using below cfg for log rotation by size but it's not working.

/var/log/nginx/access_log {
    rotate 7
    size 5k
    dateext
    dateformat -%Y-%m-%d
    missingok
    compress
    sharedscripts
    postrotate
        test -r /var/run/nginx.pid && kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

UPDATE 1:

user  nginx;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

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

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen   80;
        server_name xyz;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        location /xyz/ {
                  access_log  /var/log/nginx/access.log  main;
                  proxy_pass http://localhost:13004/xyz/;
         }
ANegi
  • 49
  • 2
  • 5
  • I've referred this - https://serverfault.com/a/427148/422461 – ANegi Jun 29 '17 at 13:23
  • Did you check in /etc/nginx/nginx.conf that is really where your pid file lives? Which OS? – JayMcTee Jun 29 '17 at 14:57
  • I've added my nginx conf and I'm using centos 7 – ANegi Jun 30 '17 at 06:38
  • There is some strangeness in nginx log rotation. I am affected by the reported bug [logrotate action "rotate" failed](https://bugs.launchpad.net/nginx/stable/+bug/1450770), not sure if it impacts your above configuration. – Paul Jul 02 '17 at 21:53

0 Answers0