欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > shell脚本配置nginx

shell脚本配置nginx

2025/6/18 1:34:20 来源:https://blog.csdn.net/weixin_74829085/article/details/143840949  浏览:    关键词:shell脚本配置nginx

read -p "请输入要部署的服务名称:" service_name      

# 2.判断服务是否安装
if rpm -q $service_name &> /dev/null;then
    echo "服务已安装"
        config_path="/www"   #自定义网站配置路径为/www
    mkdir -p $config_path #创建共享目录和网页文件
    echo "hello,this is a test page" > $config_path/index/html #写入信息
    systemctl restart $service_name    #重启服务
else
    echo "服务未安装。开始安装"
    yum install -y $service_name     #安装对应软件包
fi

if systemctl is-active  $service_name;then  #判断服务是否运行成功
    echo "服务正在运行,访问网站:http://localhost"
    curl http://localhost           #访问网站
else
    echo "服务未启动"
    cat $config_path/index.html   #显示配置文件的内容
fi

   
if systemctl is-active  $service_name;then    #如果上面都成功,发送邮件给用户  
    echo "nginx服务已成功部署并运行" | mail -s "wwb"  lxx1065372838@163.com  #发送邮件   
        mail -s "wwb的nginx脚本"    lxx1065372838@163.com  < $0      #将脚本代码发送到用户邮箱                            
fi
测试结果:

 bash wwb.sh
请输入要部署的服务名称:nginx
服务已安装
wwb.sh: line 18: /www/index/html: No such file or directory
active
服务正在运行,访问网站:http://localhost
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>Test Page for the HTTP Server on Red Hat Enterprise Linux</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style type="text/css">
            /*<![CDATA[*/
            body {
                background-color: #fff;
                color: #000;
                font-size: 1.1em;
                font-family: "Red Hat Text", Helvetica, Tahoma, sans-serif;
                margin: 0;
                padding: 0;
                border-bottom: 30px solid black;
                min-height: 100vh;
                box-sizing: border-box;
            }
            :link {
                color: #c00;
            }
            :visited {
                color: #c00;
            }
            a:hover {
                color: #f50;
            }
            h1 {
                text-align: left;
                margin: 0;
                margin-bottom: .6em;
                padding: 1em 2em 1.5em 2em;
                background-color: black;
                color: #fff;
                font-weight: normal;
                font-size: 2.5em;
                border-bottom: 2px solid #000;
            }
            h1 img {
                border: none;
                margin-bottom: .4em;
            }
            h1 strong {
                font-weight: bold;
            }
            h2 {
                font-size: 1.1em;
                font-weight: bold;
            }
            hr {
                display: none;
            }
            .content {
                padding: 1em 5em;
            }
            .content-columns {
                /* Setting relative positioning allows for 
                absolute positioning for sub-classes */
                position: relative;
                padding-top: 1em;
                display: flex;
                flex-wrap: wrap;
            }
            .content-column-left {
                /* Value for IE/Win; will be overwritten for other browsers */
                width: 47%;
                padding: 15px 30px;
                margin-right: 30px;
                padding-bottom: 2em;    
                margin-bottom: 1em;
                flex: 1;
            }
            .content-column-left hr {
                display: none;
            }
            .content-column-right {
                /* Values for IE/Win; will be overwritten for other browsers */
                width: 47%;
                padding: 15px 30px;
                padding-bottom: 2em;
                margin-right: 30px;
                margin-bottom: 1em;
                flex: 1;
            }
            .content-columns>.content-column-left, .content-columns>.content-column-right {
                /* Non-IE/Win */
                border: 1px solid #d2d2d2;
                border-radius: 3px;
                box-sizing: border-box;
            }
            .logos {
                text-align: left;
                margin-top: 2em;
            }
            .logos a img {
                padding-right: 1.5em;
                margin-right: 1.5em;
                border-right: 1px solid #d2d2d2;
            }
            img {
                border: 2px solid #fff;
                padding: 2px;
                margin: 2px;
            }
            a:hover img {
                border: 2px solid #f50;
            }
            .footer {
                font-size: xx-small;
                padding: 0 10em;
                padding-bottom: 5em;
            }

            /* Responsive layout */
            @media (max-width: 800px) {
                .content-column-right, .content-column-left {
                flex: 100%;
                }
            }
            /*]]>*/
        </style>
    </head>

    <body>
        <h1>
            <img src="system_noindex_logo.png" alt="Red Hat Logo" /><br />
            Red Hat Enterprise Linux <strong>Test Page</strong>
        </h1>

        <div class="content">
            <div class="content-middle">
                <p>This page is used to test the proper operation of the HTTP server after it has been installed. If you can read this page, it means that the HTTP server installed at this site is working properly.</p>
            </div>
            <hr />

            <div class="content-columns">
                <div class="content-column-left">
                    <h2>If you are a member of the general public:</h2>

                    <p>The fact that you are seeing this page indicates that the website you just visited is either experiencing problems, or is undergoing routine maintenance.</p>

                    <p>If you would like to let the administrators of this website know that you've seen this page instead of the page you expected, you should send them e-mail. In general, mail sent to the name "webmaster" and directed to the website's domain should reach the appropriate person.</p>

                    <p>For example, if you experienced problems while visiting www.example.com, you should send e-mail to "webmaster@example.com".</p>

                    <p>For information on Red Hat Enterprise Linux, please visit the <a href="http://www.redhat.com/">Red Hat, Inc. website</a>. The documentation for Red Hat Enterprise Linux is <a href="http://www.redhat.com/docs/manuals/enterprise/">available on the Red Hat, Inc. website</a>.</p>
                    <hr />
                </div>

                <div class="content-column-right">
                    <h2>If you are the website administrator:</h2>

                    <p>You may now add content to the webroot directory. Note
                    that until you do so, people visiting your website will see
                    this page, and not your content.</p>

                    <p>For systems using the Apache HTTP Server:
                    You may now add content to the directory <tt>/var/www/html/</tt>. Note that until you do so, people visiting your website will see this page, and not your content. To prevent this page from ever being used, follow the instructions in the file <tt>/etc/httpd/conf.d/welcome.conf</tt>.</p>

                    <p>For systems using NGINX:
                    You should now put your content in a location of your
                    choice and edit the <code>root</code> configuration directive
                    in the <strong>nginx</strong> configuration file
                    <code>/etc/nginx/nginx.conf</code>.</p>

                    <div class="logos">
                        <a href="https://access.redhat.com/products/red-hat-enterprise-linux"><img src= "/icons/poweredby.png" alt="[ Powered by Red Hat Enterprise Linux ]" /></a>
                        <img src= "poweredby.png" alt="[ Powered by Red Hat Enterprise Linux ]" />
                    </div>
                </div>
            </div>
        </div>
    <div class="footer">
        <a href="https://apache.org">Apache&trade;</a> is a registered trademark of <a href="https://apache.org">the Apache Software Foundation</a> in the United States and/or other countries.
        <br />
        <a href="https://nginx.com">NGINX&trade;</a> is a registered trademark of <a href="https://www.f5.com">F5 Networks, Inc.</a>.
    </div>
    </body>
</html>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词