源码安装nginx

1、上传nginx安装包

我的版本是nginx-1.18.0
nginx-1.18.0.tar.gz

2、下载依赖包

yum -y install gcc gcc-c++ pcre-devel zlib-devel

3、解压并检测环境

tar zxf nginx-1.18.0.tar.gz
cd nginx-1.18.0
../configure --prefix=/data/nginx --user=nginx --group=nginx --with-http_stub_status_modul

 --prefix= /usr/local/nginx ——指定安装位置
 --user=nginx  ——运行用户
-- group=nginx ——运行用户组
 --with-http_stub——状态以及模块

4、编译并安装

make && make install

5、启动

/data/nginx/sbin/nginx

6、初始化脚本

#!/bin/bash
mv -f srv/ / 2> /dev/null
[ -d /data/logs ] || mkdir -p /data/logs
[ -d /data/web/www ] || mkdir -p /data/web/www/
cat > /data/web/www/index.html  << EOF
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
EOF

7、启动脚本

#!/bin/bash
conf=/srv/nginx/conf/nginx.conf
path=/srv/nginx/sbin/nginx
pid=/data/logs/nginx.pid

ng=`netstat -nlpt | grep  nginx`
st=$?

test -x $path || exit 0

start() {
if [ $st != 0 ];then
    if [ -x $path ];then
       $path -c $conf
       echo "bingo"
    else
      if [ -e $conf ];then
        echo "nginx.conf exist"
      else
        echo "nginx.conf no"
      fi
    fi
else
  echo "running"
fi
}

stop() {
if [ -s $pid ];then
  if [ $st = 0 ];then
    $path -s stop -c $conf
    if [ $? -eq 0 ];then
      echo "death"
    else
      sleep 3
      cat $pid | xargs kill -9
    fi
  else
    echo "stopping"
  fi
else
  echo "pid no"
  pkill -9 nginx
  echo "pkill nginx"
fi
}

reload() {
if [ -s $pid ];then
  $path -s reload -c $conf
  if [ $? -eq 0 ] ;then
    echo "reload success"
  else
    echo "failure success"
  fi
else
  echo "failure success"
  echo "pid no"
fi
}

status() {
  netstat -nlpt | grep nginx > /dev/null 2>&1
  if [ $? -eq 0 ];then
    echo "alive"
  else
    echo "death"
  fi
}

case $1 in
start)
  start
;;
stop)
  stop
;;
reload)
  reload
;;
status)
  status
;;
*)
  echo "startup.sh(start|stop|reload|status)"
esac
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值