How do I automatically reload nginx when its config changes?

Quick Linux Tip #18:

Try: sudo inotifywait -m -e modify /etc/nginx/nginx.conf

Info: inotifywait monitors filesystem events using the Linux inotify kernel API. The -m option keeps it running in monitor mode.

Examples:

  • $ inotifywait -m -e modify /etc/nginx/nginx.conf | while read; do systemctl reload nginx; done
  • $ inotifywait -m -r -e create /var/incoming | while read path event file; do process "$file"; done
  • $ inotifywait -m -e close_write src/ | while read; do npm run build; done

Note: Install with sudo apt install inotify-tools. Common events include modify, create, delete, and close_write. Use -r for recursive directory watching.




LinuxTeck.com
linuxteck@ubuntu:~$ sudo inotifywait -m -e modify /etc/nginx/nginx.conf
Setting up watches.
Watches established.
/etc/nginx/ MODIFY nginx.conf
/etc/nginx/ MODIFY nginx.conf

PREVIOUS ARTICLE Quick Linux Tip #17: Are my source and backup directories truly identical? NEXT ARTICLE Quick Linux Tip #19: How do I extract just the source IPs from active connections?
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.