July 2, 2015

Auto Reload NGINX

Requirements

  • inotify-tools
  • nginx

Auto Reload NGINX

NGINX Virtual Host

[mitesh@Matrix ~]$  cat /etc/nginx/nginx.conf
##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
  • As you noticed all the Virtual Host Configuration is stored at /etc/nginx/sites-enabled/location.
  • The /etc/nginx/sites-enabled/ location contains only symbolic link of/etc/nginx/sites-available/.
For Example:
[mitesh@Matrix ~]$ ls -l /etc/nginx/sites-available/example.com
-rw-r--r-- 1 root root 418 Jun 23 18:14 /etc/nginx/sites-available/example.com
[mitesh@Matrix ~]$ ls -l /etc/nginx/sites-enabled/example.com
lrwxrwxrwx 1 root root 38 Jun 23 18:14 /etc/nginx/sites-enabled/example.com -> /etc/nginx/sites-available/example.com

Shell Script To Auto Reload NGINX

#!/bin/bash
# Check inotify-tools is installed or not
dpkg --get-selections | grep -v deinstall | grep inotify-tools &> /dev/null
if [ $? -ne 0 ]
then
        echo "Installing inotify-tools, please wait..."
        apt-get -y install inotify-tools
fi
while true
do
        inotifywait --exclude .swp -e create -e modify -e delete -e move  /etc/nginx/sites-enabled
        # Check NGINX Configuration Test
        # Only Reload NGINX If NGINX Configuration Test Pass
        nginx -t
        if [ $? -eq 0 ]
        then
                echo "Reloading Nginx Configuration"
                service nginx reload
        fi
done

Related Posts:

  • CÁCH THIẾT LẬP NGINX LÀM PROXY CHO APACHE Cách đây cũng mấy ngày rồi mình có đăng một bài case study về việc tối ưu cho một website WordPress có hàng trăm user online cùng lúc với server chỉ có 2GB RAM và 1 CPU. Do có nhiều bạn yêu cầu nên ở bài này mình sẽ hướng dẫ… Read More
  • Xử lý lỗi “502 Bad Gateway” trên Nginx Dạo gần đây có nhiều bạn thông báo hay bị lỗi 502 Bad Gateway khi sử dụng Nginx, mình đã tìm hiểu qua thông tin và có được một số giải pháp để xử lý vấn đề này như sau. – Mở file cấu hình Nginx: nano /etc/nginx/nginx.c… Read More
  • Cấu hình NGINX tối ưu cho Magento Cấu hình NGINX tối ưu cho Magento Magento là mã nguồn mở tốt nhất hiện nay để xây dựng website bán hàng (TMĐT), nếu bạn đang có ý định kinh doanh online trên Internet thì mình khuyên bạn nên bắt đầu ngay với Magento, … Read More
  • Auto Reload NGINX Requirements inotify-tools nginx Auto Reload NGINX NGINX Virtual Host [mitesh@Matrix ~]$ cat /etc/nginx/nginx.conf ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; A… Read More
  • Một số ví dụ rule Nginx Khác với Apache, Nginx không sử dụng file .htaccess nên khi bạn cần rewrite url sẽ phải convert qua rule của Nginx. Trong bài viết này, mình sẽ đưa ra một số ví dụ các rule của Nginx sử dụng để rewrite url, re… Read More

0 comments:

Post a Comment