# By default does nginx just use a single log file?

**URL:** <https://www.ruby-forum.com/t/by-default-does-nginx-just-use-a-single-log-file/225119>\
**Category:** NGINX\
**Created:** [December 14, 2012, 9:01pm UTC](https://www.ruby-forum.com/t/by-default-does-nginx-just-use-a-single-log-file/225119 "2012-12-14T21:01:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [December 14, 2012, 9:01pm UTC](https://www.ruby-forum.com/t/by-default-does-nginx-just-use-a-single-log-file/225119/1 "2012-12-14T21:01:29Z")

</div>

By default does nginx just keep appending to the same log file? (for  
both  
access and error log files)

Is there a reason why there is no built in way of having it create a new  
file per day/hour or something? I guess the idea is to keep the feature  
set very lean?

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [December 14, 2012, 9:21pm UTC](https://www.ruby-forum.com/t/by-default-does-nginx-just-use-a-single-log-file/225119/2 "2012-12-14T21:21:21Z")

</div>

On Fri, Dec 14, 2012 at 03:00:53PM -0500, S Ahmed wrote:

Hi there,

> By default does nginx just keep appending to the same log file? (for both  
> access and error log files)

Yes. (Although the access log file name can include per-request  
variables.)

> Is there a reason why there is no built in way of having it create a new  
> file per day/hour or something? I guess the idea is to keep the feature  
> set very lean?

Would you like it per day or per hour? Or every 4 MB, or every 1 million  
lines? (Or every second Tuesday unless the moon is full?) There are too  
many possibly-useful rules for anything built-in to satisfy everybody.

So nginx allows you to choose whatever combination of circumstances you  
want, outside of nginx, and then provides a well-defined way for you to  
induce a log file rotation.

> **[Controlling nginx](http://nginx.org/en/docs/control.html#logs)**
>
> nginx can be controlled with signals. The process ID of the master process is written to the file /usr/local/nginx/logs/nginx.pid by default. This name may be changed at configuration time, or in nginx.conf using the pid directive. The master process...

That’s my understanding, anyway.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [December 14, 2012, 10:11pm UTC](https://www.ruby-forum.com/t/by-default-does-nginx-just-use-a-single-log-file/225119/3 "2012-12-14T22:11:01Z")

</div>

only on a full moon, excluding leap years. thank you and when can I  
expect  
this feature? 🙂

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [December 14, 2012, 10:43pm UTC](https://www.ruby-forum.com/t/by-default-does-nginx-just-use-a-single-log-file/225119/4 "2012-12-14T22:43:09Z")

</div>

Nginx doesn’t include periodic log rotation functionality, the only  
thing  
included is reopening the log files on USR1 signal, so one may rename  
the  
current log file and then kill -USR1 `cat /var/run/nginx.pid` for nginx  
to  
create a new log (see [Log Rotation | NGINX](http://wiki.nginx.org/LogRotation) ). External  
tools  
may be used to do the actual period rotation, like in Linuxish world  
it’s  
normally done by logrotate (  
[http://manpages.ubuntu.com/manpages/lucid/man8/logrotate.8.html](http://manpages.ubuntu.com/manpages/lucid/man8/logrotate.8.html) ) - in  
recent Ubuntu versions it’s already set up to rotate default nginx log  
files.

2012/12/14 S Ahmed [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [December 15, 2012, 10:45am UTC](https://www.ruby-forum.com/t/by-default-does-nginx-just-use-a-single-log-file/225119/5 "2012-12-15T10:45:08Z")

</div>

On Dec 15, 2012, at 2:10 , S Ahmed wrote:

> 1. kill -USR1 ‘cat /var/run/nginx.pid’
> 2. profit

1. rename file
2. kill -USR1 ‘cat /var/run/nginx.pid’
3. sleep 2
4. do everything with the file: gzipping, moving to other host, etc.

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [December 15, 2012, 7:20pm UTC](https://www.ruby-forum.com/t/by-default-does-nginx-just-use-a-single-log-file/225119/6 "2012-12-15T19:20:56Z")

</div>

I see, thanks.

So there is there a small window of time when the logs will not be  
written  
or lost?

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [December 14, 2012, 11:11pm UTC](https://www.ruby-forum.com/t/by-default-does-nginx-just-use-a-single-log-file/225119/7 "2012-12-14T23:11:12Z")

</div>

m irya,

Thanks. I’m planning to run 12.04 ubuntu.

What exactly does ‘re-opening’ of a log file mean? Isn’t it already  
open,  
meaning nginx has it open and is appending to it?

So step by step, what is to be done?

1. kill -USR1
2. rename file?
3. kill -USR1 ‘cat /var/run/nginx.pid’
4. profit

?

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [December 15, 2012, 9:32pm UTC](https://www.ruby-forum.com/t/by-default-does-nginx-just-use-a-single-log-file/225119/8 "2012-12-15T21:32:20Z")

</div>

No, logs are always written either in renamed old file or created newly  
by master process.  
There is window between sending signal and reopening new files by worker  
processes.

–  
Igor S.

> **[Technical Support for NGINX and NGINX Plus Software](https://www.nginx.com/support/)**
>
> Get the help you need with support directly from the authors and maintainers of NGINX Open Source and NGINX Plus.
