首页 / NGINX / 自动安装nginx脚本
自动安装nginx脚本
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了自动安装nginx脚本,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2720字,纯文字阅读大概需要4分钟。
内容图文
![自动安装nginx脚本](/upload/InfoBanner/zyjiaocheng/926/da0e076286f8477297e8569921b7d3c1.jpg)
1、自动安装nginx脚本,添加虚拟nginx配置文件
#!/bin/bash
#2021-3-17 16:53:06
#Automatically configure the NGINX virtual service
#by author shinian
#########################
NGINX_VER="1.9.9"
NGINX_CNF="nginx.conf"
NGINX_SOFT="nginx-${NGINX_VER}.tar.gz"
NGINX_DIR="/usr/local/nginx"
NGINX_URL="http://nginx.org/download"
NGINX_SRC=$(echo $NGINX_SOFT|sed 's/.tar.*//g')
function nginx_help(){
echo -e "\033[33mNginx VIrtual Manager SHELL Scripts\033[0m"
echo -e "\033[33m-------------------------------\033[0m"
echo -e "\033[33m1)-A New Install Nginx WEB Server.\033[0m"
echo -e "\033[33m2)-B v1.www.com|v2.www.com v3.www.com\033[0m"
echo -e "\033[33m3)-C v1.www.com|v2.www.com v3.www.com\033[0m"
echo -e "\033[35mUsage:{/bin/bash $0 -A(Install) -B(add) or -C(del) -H(help)\033[0m"
exit 0
}
function nginx_install(){
#Nginx Install Config
if [ ! -d ${NGINX_DIR} ];then
wget -c $NGINX_URL/$NGINX_SOFT
tar -xzf $NGINX_SOFT
yum install pcre-devel zlib-devel -y
cd nginx-${NGINX_VER}
./configure --prefix=${NGINX_DIR}/.
make
make install
${NGINX_DIR}/sbin/nginx
ps -ef|grep nginx
netstat -tnlp|grep 80
setenforce 0
systemctl stop firewalld.service
else
echo -e "\033[33m-----------------------\033[0m"
echo -e "\033[32mThe Nginx WEB Already Install,Please Exit.\033[0m"
fi
}
function virtual_add(){
#Nginx Config Virtual Host
if [ $# -le 1 ];then
nginx_help
fi
cd ${NGINX_DIR}/conf/
grep "include domains" ${NGINX_CNF} >>/dev/null 2>&1
if [ $? -ne 0 ];then
grep -vE "^$|#" ${NGINX_CNF} > ${NGINX_CNF}.swp
\cp ${NGINX_CNF}.swp ${NGINX_CNF}
sed -i '/server/,$d' ${NGINX_CNF}
echo -e -e " include domains/*;\n}" >>${NGINX_CNF}
${NGINX_DIR}/sbin/nginx -t
mkdir domains -p
fi
shift 1
NUM=`ls domains/|grep -c $*`
if [ $NUM -eq 0 ];then
cat>domains/$*<<EOF
server {
listen 80;
server_name $*;
location / {
root html/$*;
index index.html index.htm;
}
}
EOF
mkdir -p ${NGINX_DIR}/html/$*
cat>${NGINX_DIR}/html/$*/index.html<<EOF
<h1>$* Welcome to nginx!</h1>
<hr color=red>
EOF
echo -e "\033[32m-----------------------\033[0m"
echo -e "\033[32mThe Nginx $* ADD Success.\033[0m"
cat domains/$*
echo -e "\033[32m-----------------------\033[0m"
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
echo
else
echo -e "\033[32m-----------------------\033[0m"
echo -e "\033[32mThe Nginx $* Already Exist,Please Exit.\033[0m"
cat domains/$*
exit 1
fi
}
function virtual_del(){
cd ${NGINX_DIR}/conf/domains/
shift 1
ls -l|grep "$*"
if [ $? -eq 0 ];then
rm -rf $*
/usr/local/nginx/sbin/nginx -s reload
fi
}
case $1 in
-A)
nginx_install
;;
-B)
virtual_add $*
;;
-C)
virtual_del $*
;;
*)
nginx_help
esac
.
.
.
最后:
本人为纯小白,所写博客为个人学习记录,如某些地方编写有错误,或者涉及侵权的请联系我删除或修改。
Q Q:7721552
邮箱:7721552@qq.com
内容总结
以上是互联网集市为您收集整理的自动安装nginx脚本全部内容,希望文章能够帮你解决自动安装nginx脚本所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。