日常笔记

Linux简单配置Apache脚本

2017-05-13  本文已影响11人  Lisong
#!/bin/bash
cat << EOF
软件安装
服务重启
EOF
rpm -q httpd
if [[ $? -eq 0 ]];then
    echo "apche 已安装"
else
    yum install -y httpd
    if [[ $? -eq 0 ]];then
        echo "软件安装成功"
    else
        echo "软件安装失败"
    fi
fi
service httpd restart
#curl 127.0.0.1
wget 127.0.0.1
if [[ $? -eq 0 ]];then
    echo "重启成功"
else
    echo "重启失败"
fi
cd /etc/httpd/conf
test -e /etc/httpd/conf/httpd.conf.bak || cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

echo "配置虚拟目录"
read -p "监听端口:" -t 20 lp
read -p "虚拟主机IP" -t 20 vip
while true; do
read -p "虚拟主机根目录" -t 20  rdir 
if [[  -d  /web1/${rdir} ]];then
    echo "目录存在"
else
    mkdir -p /web1/${rdir}
    if [[ $? -eq 0 ]];then
        echo "目录创建成功"
        break;
    fi
fi
done
read -p " 虚拟主机名:" -t 20 vn

cat <<- EOF >> httpd.conf
Listen ${lp}
<VirtualHost ${vip}:${lp} >
DocumentRoot ${rdir}
ServerName ${vn}
ErrorLog "logs/${vip}-err.log"
CustomLog "logs/${vip}-acc.log" common
<Directory ${rdir} >
AllowOverride None
Rquire all granted
</Directory >
</VirtualHost>
EOF
service httpd restart
curl 127.0.0.1:${lp}
if [[ $? -eq 0 ]];then
    echo "服务配置成功"
else
    echo "配置失败"
fi
sleep 3s

上一篇下一篇

猜你喜欢

热点阅读