环境准备&&安装nginx
#关闭selinux setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#创建运行用户 useradd -M -s /sbin/nologin nginx
#添加epelyum源 wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
#安装依赖包 yum -y install wget unzip bzip2 zlib zlib-devel pcre pcre-devel \ openssl openssl-devel geoip geoip-devel gd gd-devel gcc gcc-c++ make libtool
#包存放目录 mkdir /source && cd /source
#安装配置支持包 wget https://www.jinchuang.org/novel/lnmp/pcre-8.35.tar.gz wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz wget https://www.jinchuang.org/novel/lnmp/zlib-1.2.8.tar.gz
#解压 tar xf pcre-8.35.tar.gz tar xf openssl-1.0.2h.tar.gz tar xf zlib-1.2.8.tar.gz
wget http://nginx.org/download/nginx-1.14.1.tar.gz
tar xf nginx-1.14.1.tar.gz
cd nginx-1.14.1
#配置:【注意:pcre,openssl,zlib路径填写源码包路径不是编译安装后路径】
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/usr/local/nginx/client_temp \
--http-proxy-temp-path=/usr/local/nginx/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-mail \
--with-stream \
--with-threads \
--with-file-aio \
--with-poll_module \
--with-select_module \
--with-http_v2_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_geoip_module \
--with-http_slice_module \
--with-http_gunzip_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_image_filter_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_stub_status_module \
--with-mail_ssl_module \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module \
--with-pcre=/source/pcre-8.35 \
--with-openssl=/source/openssl-1.0.2h \
--with-zlib=/source/zlib-1.2.8
make && make install
vim /etc/profile #文件最后添加一行 export PATH=$PATH:/usr/local/nginx/sbin
#重新读取文件 source /etc/profile
或者 echo 'export PATH=$PATH:/usr/local/nginx/sbin' >>/etc/profile && source /etc/profile
[root@localhost ~]# nginx [root@localhost ~]# netstat -lntp |grep nginx
安装依赖包
systemctl stop firewalld
systemctl disable firewalld
setenforce 0 && sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache
yum install dh-autoreconf fcgi fcgi-devel -y
安装spawn-fcgi 和 fcgiwrap
#创建存放包的目录(包下载到哪个目录都可以,这里放在/source/目录下) mkdir /source/ && cd /source/ #安装spawn-fcgi #github下载最新代码 https://github.com/lighttpd/spawn-fcgi 本地下载:wget https://www.jinchuang.org/novel/lnmp/spawn-fcgi.zip 解压:unzip spawn-fcgi.zip 安装: mv spawn-fcgi-master spawn-fcgi cd spawn-fcgi ./autogen.sh ./configure make && make install #安装fcgiwrap #github下载最新代码 https://github.com/gnosek/fcgiwrap 本地下载:wget https://www.jinchuang.org/novel/lnmp/fcgiwrap.zip 解压: unzip fcgiwrap.zip 安装: mv fcgiwrap-master fcgiwrap cd fcgiwrap autoreconf -i ./configure make && make install
创建fcgiwrap启动脚本
cd /etc/init.d/ vim 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 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
启动fcgiwrap服务
#增加可执行权限 chmod +x /etc/init.d/fcgiwrap #添加到服务里面(centos6系统执行,centos7跳过此步骤) chkconfig --add fcgiwrap chkconfig --level 2345 fcgiwrap on #启动服务 /etc/init.d/fcgiwrap start Starting fcgiwrap... spawn-fcgi: child spawned successfully: PID: 22416 spawn-fcgi: child spawned successfully: PID: 22417 spawn-fcgi: child spawned successfully: PID: 22418 spawn-fcgi: child spawned successfully: PID: 22419 spawn-fcgi: child spawned successfully: PID: 22420 done
nginx配置转发
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #注意下修改为你的目录路径 #location ~ ^/linux-shell/page/script/.*\.(cgi) { #这里的cgi后缀匹配根据需要修改,后缀自定义即可 # linux-shell 为模板程序目录,放在nginx网站根目录下面 location ~ ^/linux-shell/page/script/ { #我这里调用的文件是没有后缀的就用这个配置 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 |
5,模板目录结构(文章最下面下载模板)
# 下载模板,放在在网站根目录下 # 目录结构: linux-shell ├── css │ ├── iconfont.css │ ├── iconfont.eot │ ├── iconfont.svg │ ├── iconfont.ttf │ ├── iconfont.woff │ ├── iconfont.woff2 │ ├── page.css │ └── style.css ├── favicon.ico ├── images │ ├── b.jpg │ ├── body.cur │ ├── b.png │ ├── content.jpg │ ├── hua.gif │ ├── link.cur │ ├── logo.png │ ├── nav.jpg │ └── page.cur ├── index.html ├── js │ ├── jquery-2.1.1.min.js │ └── nav.js └── page ├── content │ ├── index.html │ ├── script.js │ └── TweenMax.min.js ├── h5 │ ├── 161 │ │ └── 161.html │ ├── 188 │ │ └── 188.html │ └── local │ └── local.html └── script ├── 161 │ ├── disk │ ├── info │ ├── mem │ ├── ps │ ├── server │ ├── ssh │ └── uptime ├── 188 │ ├── disk │ ├── info │ ├── mem │ ├── ps │ ├── server │ ├── ssh │ └── uptime └── local ├── disk ├── info ├── mem ├── ps ├── server ├── ssh └── uptime
shell代码示例文件
#!/bin/bash echo "Content-Type:text/html;charset=utf-8" echo "" # 自动刷新 #echo "<script>window.setInterval(function(){ # window.location.reload(); #},1000);</script>" #echo "<meta http-equiv="refresh" content="60">" # html页面css样式 echo '<style> body{color:#cecece;} .title{color: #FF9800;border-left: 4px solid;padding: 4px;} pre{font-size:14px;border-left: 4px solid #4CAF50;padding: 5px;} </style>' # 定义变量 ip="192.168.x.x" # 内容代码(命令返回结果放在 <pre>标签中) echo '<div style="padding-left:10px;">' echo '<h1 class="title">硬盘使用情况</h1>' echo '<h5 style="color:#848484;">' dd=`date` echo "统计时间: $dd 【当前机器ip: $ip】" echo '</h5>' echo ' <pre>' # 查看磁盘使用(本机) df -hT # 查看磁盘使用(远程机器,可以使用ansible|sshpass等远程工具) sshpass -p "password" ssh root@$ip -o StrictHostKeyChecking=no 'df -hT' echo '</pre> '
https://files.cnblogs.com/files/blogs/725965/linux-shell.zip?t=1687154674&download=true
访问方式:http://192.21.11.99/linux-shell/
分类:
nginx
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)