Script in linux monitors nginx status and restarts

        First of all, you need to determine the installation location of nginx. If you customize the installation, you need to find the location of the nginx running program. The following writing and execution are all compiled and installed by nginx from the source code. The location of the running program is: /usr/local/ nginx/sbin/nginx

To determine the port used by nginx, you can first find the process pid of nginx ps -ef|grep nginx

 Then check the listening port of nginx through ps aux|grep nginx, here is 80

 Determine the directory where the written script is located: /etc/nginx

 The directory where the log is located: /etc/nginx/nginx.check.logs/

Write the script vim nginx_check.sh, if it prompts that there is no vim, you can execute yum install vim to install

#!/bin/bash
date=`date +%Y-%m-%d`
date_time=`date +%Y-%m-%d_%H:%M:%S`
logs_back=/etc/nginx/nginx.check.logs
logs_file=$logs_back/$date.nginx.check.logs
mkdir -p /etc/nginx/nginx.check.logs
touch $logs_file
nginx_po

Guess you like

Origin blog.csdn.net/xtldcn/article/details/130386994