Linux简单配置Apache脚本

#!/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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容