一键安装nginx
vim install_nginx.sh
#!/bin/bash
#定义变量
NGINX_VERSION=1.20.2
INSTALL_DIR=/apps/nginx
install_nginx(){
#下载tar包
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz || { echo "下载失 败!";exit 20; }
#解压tar包
tar xf nginx-${NGINX_VERSION}.tar.gz -C /usr/local/src
#安装必要的依赖
yum -y install gcc openssl-devel pcre-devel
cd /usr/local/src/nginx-${NGINX_VERSION}
#编译执行
./configure --prefix=${INSTALL_DIR} --with-http_ssl_module
make -j `grep -c processor /proc/cpuinfo`&& make install
if [ $? -ne 0 ];then
echo Install nginx is failed!
exit 10
else
echo "Install nginx is finished!"
fi
}
start_nginx(){
echo "<h1>welcome to M49 nginx website </h1>" > ${INSTALL_DIR}/html/index.html
/apps/nginx/sbin/nginx
}