#先新建文件
sudo vim ./install-nginx.sh
#1.不多说,上代码
#!/bin/bash
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 -y aptitude -y libssl-dev
sudo apt-get install -y openssl
sudo apt-get install -y zlib1g.dev
sudo apt-get install -y libssl-dev
cd "./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
sudo ln -s "$installDir"/sbin/* /usr/sbin
sudo nginx
#2.命令
sudo chmod +x ./install-nginx.sh
sudo ./install-nginx.sh
#./install-nginx.sh 1.17.3 /usr/local/nginx