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