Shell 脚本一键编译并且安装 nginx
2020-06-13 本文已影响0人
Renew全栈工程师
先新建文件
vim ./install-nginx.sh
1.不多说,上代码
#!/bin/sh
version=$1;
if [ -z "$version" ]; then
version="1.17.3"
fi
installDir="$2"
if [ -z "$installDir" ]; then
installDir="/usr/local/nginx"
fi
fileName="nginx-$version.tar.gz"
if ! wget -O "$fileName" "https://nginx.org/download/$fileName"; then echo "wget download nginx-$version fail"; exit 1; fi
if [ ! -f "$fileName" ]; then echo "$fileName not found"; exit 1; fi
if ! tar -zxvf "$fileName"; then echo "decompression fail"; exit 1; fi
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y libpcre3-dev aptitude libssl-dev
sudo apt-get install -y openssl
sudo apt-get install -y zlib1g.dev
sudo apt-get install -y libssl-dev
"./nginx-$version/configure" --prefix="$installDir" --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
sudo make && sudo make install
echo export PATH=\$PATH:"$installDir/sbin" >>/etc/profile
source /etc/profile
ln "$installDir/sbin" /usr/bin
sudo nginx
2.命令
chmod -x ./install-nginx.sh
./install-nginx.sh
#./install-nginx.sh 1.17.3 /usr/local/nginx