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?
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" ”.
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.