nginx安装脚本(Ubuntu)

apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g zlib1g-dev
# Ubuntu14.04的仓库中没有发现openssl-dev,由下面openssl和libssl-dev替代
#apt-get install openssl openssl-dev
sudo apt-get install openssl
sudo apt-get install libssl-dev

NGINX=http://nginx.org/download/nginx-1.20.1.tar.gz
NGINX_BACKAGE=`echo $NGINX | awk -F "/" '{print $5}' `
NGINX_NAME=`echo $NGINX_BACKAGE | awk -v joinstr="." -F "." '{print $1.joinstr$2.joinstr$3 }' `
echo "链接:$NGINX"
echo "提取:$NGINX_BACKAGE  $NGINX_NAME"
if [ ! -f $NGINX_BACKAGE ]; then
    echo "不已存在!包,准备下载..."
    wget $NGINX

fi
tar -zxvf $NGINX_BACKAGE
#指定安装目录
echo "安装中..."
cd $NGINX_NAME
mkdir /usr/local/nginx
./configure --prefix=/usr/local/nginx/$NGINX_NAME
make
make install

echo -n "修改端口?n不需要自定义,输入数字配置端口(no/number):" ;read CONFIG_PORT
if [ -n "$(echo $CONFIG_PORT| sed -n "/^[0-9]\+$/p")" ]  && [ $CONFIG_PORT -ge 0 ]  && [ $CONFIG_PORT -le 65535 ] ; then
  echo "你输入的$CONFIG_PORT有效,正在配置..."
  sed -i  "s/listen       80\;/listen       $CONFIG_PORT \;/" ./conf/nginx.conf
  echo "配置完成..."
fi

echo "启动中..."
cd /usr/local/nginx/$NGINX_NAME/sbin
./nginx
#检验
echo "检验中..."
./nginx -t

 

写到:nginx_install.sh

授权:sudo chmod 777 ./nginx_install.sh

执行:./nginx_install.sh

posted @ 2021-06-12 12:44  小庄的blog  阅读(189)  评论(0编辑  收藏  举报