Shell script to create nginx upstream and location configuration file

Source: Internet
Author: User
Tags egrep

#!/bin/SH###################################################### name:create_nginx_conf.SH# VERSION:V1.0# Author: OPS Rookie # Description: Creating Nginx-related Profiles # Create Date: .- --Geneva# Email: ######################################################Env. sh File Content format:10.10.2.6=basics-price-Service; #function_name: The method to invoke Function_name=$1#ns_type: Project Environment name Ns_type=$2#env_file:Env. sh file specific path Env_file_path=$3#判断env. SH is presentfunctionCheck_env_file () {if[-F ${env_file_path}]; Then        Echo "The ${env_file_path} is exist."        Echo-E"\ n"    Else        Echo "The ${env_file_path} is not exist."Exit1    fi} #生成nginx的location段的配置文件functioncreate_location () { forPoolinch`Cat${env_file_path} |Cut-D"="-f2 |Cut-D";"-f1 |Sort|Uniq`; Do        Echo-E"Location /${pool} {\n\tproxy_pass http://${ns_type}-${pool}/${pool};\n\tproxy_set_header Host \ $host; \n\tproxy_ Set_header x-real-ip \ $remote _addr;\n\tproxy_set_header x-forwarded-for \ $proxy _add_x_forwarded_for;\n\tbreak;\n} "      Done} #生成nginx的upstream配置文件functioncreate_upstream_conf () { forPoolinch`Cat${env_file_path} |Cut-D"="-f2 |Cut-D";"-f1 |Sort|Uniq`; Doip_list=`Cat${env_file_path} |Egrep "${pool};"|Cut-D"="-f1 |Sort|Uniq' #pool_port=`Cat Env.SH|Egrep "${pool}="|Cut-D"="-f3 |Cut-D";"-f1|Sort|Uniq`        Echo-E"upstream ${ns_type}-${pool} {"         forIpinch${ip_list[*]}; Do            Echo-E"\tserver ${ip}:8080;"         Done        Echo  "}"     Done}if[$#-eq3]; Then     Case$1 inchLocation ) Check_env_file;            Create_location;        ;;            Upstream) Check_env_file;            create_upstream_conf;        ;; *)            $"Usage: {sh create_nginx_conf.sh location hh-prod/data/env.sh|sh create_nginx_conf.sh upstream hh-prod/data/ ENV.SH}"Exit3    EsacElse    Echo "variables count not eq 5.please Check the usage."    Echo "Usage: {sh create_nginx_conf.sh location hh-prod/data/env.sh|sh create_nginx_conf.sh upstream hh-prod/data/ env.sh}."fi

Shell script to create nginx upstream and location configuration file

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.