标签:格式 支持 location 统计 user sed 统一 des sleep
一直以来都是在终端执行shell等脚本,那web界面是否也可以这样,当然也是可以的
本文以centos 6为例安装配置
#! /bin/bash ### BEGIN INIT INFO # Provides: fcgiwrap # Required-Start: $remote_fs # Required-Stop: $remote_fs # Should-Start: # Should-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: FastCGI wrapper # Description: Simple server for running CGI applications over FastCGI ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin SPAWN_FCGI="/usr/local/bin/spawn-fcgi" DAEMON="/usr/local/sbin/fcgiwrap" NAME="fcgiwrap" PIDFILE="/var/run/$NAME.pid" FCGI_SOCKET="/tmp/$NAME.socket" FCGI_USER="nginx" FCGI_GROUP="nginx" FORK_NUM=5 SCRIPTNAME=/etc/init.d/$NAME case "$1" in start) echo -n "Starting $NAME... " PID=`pidof $NAME` if [ ! -z "$PID" ]; then echo " $NAME already running" exit 1 fi $SPAWN_FCGI -u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -P $PIDFILE -F $FORK_NUM -f $DAEMON if [ "$?" != 0 ]; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Stoping $NAME... " PID=`pidof $NAME` if [ ! -z "$PID" ]; then kill `pidof $NAME` if [ "$?" != 0 ]; then echo " failed. re-quit" exit 1 else rm -f $pid echo " done" fi else echo "$NAME is not running." exit 1 fi ;; status) PID=`pidof $NAME` if [ ! -z "$PID" ]; then echo "$NAME (pid $PID) is running..." else echo "$NAME is stopped" exit 0 fi ;; restart) $SCRIPTNAME stop sleep 1 $SCRIPTNAME start ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|status}" exit 1 ;; esac
chmod +x /etc/init.d/fcgiwrap
location ~ ^/cgi-bin/cgi/.*\.(cgi|sh) { #这里的后缀匹配根据需要修改,可以使用统一cgi后缀 gzip off; fastcgi_pass unix:/tmp/fcgiwrap.socket; fastcgi_index index.cgi; include fastcgi_params; fastcgi_param SCRIPT_NAME $document_root$fastcgi_script_name; }
重启nginx:
nginx -s reload
mkdir -p /usr/share/nginx/html/cgi-bin 放置首页html
mkdir -p /usr/share/nginx/html/cgi-bin/cgi 放置脚本
#!/bin/bash echo "Content-Type:text/html;charset=utf-8" echo "" #前3行必须是这个格式,html代码使用echo,linux命令和脚本语法一样 echo ‘<div style="padding-left:10px;">‘ echo ‘<h1 style="color:red;border-left:4px solid;padding:4px;">硬盘使用情况</h1>‘ echo ‘<h5>‘ dd=`date` echo "统计时间: $dd" echo ‘</h5>‘ echo ‘<pre style="border-left: 4px solid rgb(12, 40, 245);padding:5px">‘ df -hT echo ‘</pre>‘
访问:http://your-ip/cgi-bin/cgi/disk.cgi
标签:格式 支持 location 统计 user sed 统一 des sleep
原文地址:http://www.cnblogs.com/Mrhuangrui/p/7800288.html