Nginx Support Web Interface Execution Bash script

Source: Internet
Author: User

has always been in the terminal execution shell and other scripts, whether the Web interface can also do so, of course, is also possible
This article takes CentOS 6 as an example to install the configuration

  1. Installing spawn-fcgi
    wget Https://github.com/lighttpd/spawn-fcgi/archive/spawn-fcgi-1.6.4.zip
    Unzip Spawn-fcgi-1.6.4.zip && RM spawn-fcgi-1.6.4.zip
    MV spawn-fcgi-spawn-fcgi-1.6.4/spawn-fcgi
    CD spawn-fcgi/
    ./autogen.sh
    ./configure
    Make && make install
  2. Installing Fcgiwrap
    Yum-y Install fcgi fcgi-devel nginx
    wget Https://github.com/gnosek/fcgiwrap/archive/1.1.0.zip
    Unzip 1.1.0.zip
    RM 1.1.0.zip
    MV Fcgiwrap-1.1.0/fcgiwrap
    CD fcgiwrap/
    Autoreconf-i
    ./configure
    Make && make install
  3. Add Fcgiwrap startup script
    Script enable user to be consistent with your Nginx boot user, note the path in the script and start the user
    Vim/etc/init.d/fcgiwrap
    #! /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 forrunning CGI applications over fastcgi### END INIT INFOPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binspawn_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=5ScriptName=/etc/init.d/$NAME Case " $" inchstart)Echo-N"starting $NAME ..."PID=`pidof$NAME 'if[!-Z"$PID"]; Then            Echo "$NAME already running"Exit1        fi$SPAWN _fcgi-U $FCGI _user-g $FCGI _group-s $FCGI _socket-p $PIDFILE-F $FORK _num-F $DAEMONif["$?"!=0]; Then            Echo "failed"Exit1        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"Exit1            Else                RM-F $pidEcho " Done"            fi        Else            Echo "$NAME is not running."Exit1        fi    ;; Status) PID=`pidof$NAME 'if[!-Z"$PID"]; Then            Echo "$NAME (PID $PID) is running ..."        Else            Echo "$NAME is stopped"Exit0        fi    ;; Restart) $SCRIPTNAME StopSleep 1$SCRIPTNAME start;; *)        Echo "Usage: $SCRIPTNAME {start|stop|restart|status}"Exit1    ;;Esac
    Fcgiwrap

    chmod +x/etc/init.d/fcgiwrap

  4. Start
    Chkconfig--add Fcgiwrap
    Chkconfig--level 2345 Fcgiwrap on
    ./etc/init.d/fcgiwrap Restart
  5. Nginx Configuration
    Test environment Edit/etc/nginx/conf.d/default.conf, add
        Location ~ ^/cgi-bin/cgi/.*\. (cgi| SH {  #这里的后缀匹配根据需要修改, you can use the unified CGI        suffix gzip  off;        Fastcgi_pass Unix:/tmp/fcgiwrap.socket;        Fastcgi_index index.cgi;        Include Fastcgi_params;        Fastcgi_param  script_name $document _root$fastcgi_script_name;    }

    Restart Nginx:
    Nginx-s Reload
    Mkdir-p/usr/share/nginx/html/cgi-bin Place Home HTML
    Mkdir-p/usr/share/nginx/html/cgi-bin/cgi Placement Script

  6. Script Test
    vim/usr/share/nginx/html/cgi-bin/cgi/disk.cgi
    #!/bin/BashEcho "Content-type:text/html;charset=utf-8"Echo ""#前3行必须是这个格式, the HTML code uses the Echo,linux command as well as the scripting syntaxEcho '<div style= "padding-left:10px;" >'Echo '

    'Echo ''DD=`Date`Echo "Statistics Time: $dd"Echo ''Echo '<pre style= "border-left:4px solid RGB (A, A, 245);p adding:5px" >'DF-HTEcho '</pre>'

    disk.cgi

    Visit: http://your-ip/cgi-bin/cgi/disk.cgi

Nginx Support Web Interface Execution Bash script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.