Home  >  Q&A  >  body text

How does Nginx write log files?

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?

天蓬老师天蓬老师2712 days ago734

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 17:32:10

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

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 17:32:10

    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.

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-16 17:32:10

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

    reply
    0
  • Cancelreply