How does Nginx write log files?
天蓬老师
天蓬老师 2017-05-16 17:30:10
0
3
759

While doing Nginx log file cutting, I discovered a strange problem. When I manually move the Nginx log file to another location, if I do not reload the configuration file, Nginx will continue to write the log file that was moved to another directory.
Doesn’t Nginx use the file path when writing logs?
Why can the log file still be written to after being moved?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
Ty80

This is a feature of the file system, somewhat similar to reference counting in a programming language that manages the life cycle of variables. Move a file, or even delete a file, as long as the file is still open by a process, the file can still be accessed. But if all the "references" are gone, such as the file name, hard link and file handle (no longer open by the program), then the next reference to the file will be affected, and it will appear as "File not found" ”.

Ty80

I think the reason is that after nginx opens the log file, it is actually identified by inode in the system. Moving the file will not modify the inode number, so the file will continue to be written.

滿天的星座

nginx generally caches the inode of the file for faster speed.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template