SHELL automatically deploys nginx and sets up a virtual host

Source: Internet
Author: User

Maple City Prodigal Original, reproduced please indicate the source!

For more technical blog posts, see Personal blog: https://fengchenglangzi.000webhostapp.com

bh19890922

QQ445718526, 490425557

650) this.width=650; "Src=" https://fengchenglangzi.000webhostapp.com/wp-content/uploads/2017/08/083017_0600_ Shellnginx1.png "style=" Padding:0px;margin:0px;border:0px;height:auto; "/>

#!/bin/bash#2017-8-29 16:07:07#by fengchenglangzi#auto install nginx and vhost## ################# #定义变量SOFT_DIR = "/usr/local/src" nginx_dir= "/usr/local/nginx" nginx_soft= "nginx-1.12.0.tar.gz" nginx_soft_name=$ (echo  $NGINX _soft|awk -f ". Tar"   ' {print $1} ') yum= "yum install -y "Pcre_gcc=" Gcc gcc-c++ pcre pcre-devel openssl-devel "################### #安装Nginxfunction  Install_Nginx  ()  {        if [ ! -d   $NGINX _dir ];then                  $YUM   $PCRE _gcc                 cd  $SOFT _dir                 if [ ! -d  $SOFT _dir/$NGINX _soft_name ];then       &nbSp;                 wget  -c http://nginx.org/download/$NGINX _soft                         tar -zxf $ Nginx_soft                fi                 cd  $NGINX _soft_name                sed  -i -e  ' s/1.12.0//g '  -e  ' s/nginx\//jws/g '  -e  ' s/' nginx '/' JWS '/g '  src/ core/nginx.h                 useradd nginx;usermod -s /sbin/nologin nginx            &nBsp;    ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx  --with-http_stub_status_module  --with-http_ssl_module && make -j8  && make install -j8                 if [ $? -eq 0 ];then                          echo  "Nginx installation is complete!!! "                        /usr/local/nginx/sbin/nginx                 fi        else                 echo  "Nginx is installed!!! "        fi}#################### #创建虚拟主机function  create_vhost   ()  {        if [ ! -d  $NGINX _dir ] ; Then                echo   "The current system is not installed Nginx, please first install nginx!!! "        else                 read -p  "Please enter a new virtual host domain name:"  input                 domain_name= ($ (echo  $input))                 i=0                 while [[ $ i < ${#DOMAIN_NAME [@]} ]]                do                 if [ ! -d  $NGINX _dir/conf/vhost/${domain_name[i]} ];then                 mkdir -p $ nginx_dir/conf/vhost/${domain_name[i]}/{logs,html}                 touch  $NGINX _dir/conf/vhost/${domain_name[i]}/nginx.conf                 sed -i  "/include  * mime.types/a\include  $NGINX _dir\/conf\/vhost\/${domain_name[i]}/nginx.conf; "   $NGINX _dir/conf/nginx.confcat >>  $NGINX _dir/conf/vhost/${domain_name[i]}/nginx.conf  << EOFserver {        listen        80;        server_name  ${DOMAIN_NAME[i]};         access_log   $NGINX _dir/conf/vhost/${domain_name[i]}/logs/access.log;         location / {             root    $NGINX _dir/conf/vhost/${domain_name[i]}/html/;             index  index.html index.htm;         }}EOFcat >>  $NGINX _dir/conf/vhost/${domain_name[i]}/html/ index.html << eof<! Doctype html>


This article is from the "Maple City Prodigal" blog, please be sure to keep this source http://fengchenglangzi.blog.51cto.com/1322043/1961308

SHELL automatically deploys nginx and sets up a virtual host

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.