#!/bin/sh
#####################################################
# Name: create_nginx_conf.sh
# Version: V1.
# Author: 运维菜鸟
# Description: 创建nginx相关配置文件
# Create Date: --
# Email:
##################################################### #env.sh文件内容格式:10.10.2.6=basics-price-service; #function_name:要调用的方法
function_name=$
#ns_type:项目环境名称
ns_type=$
#env_file:env.sh文件具体路径
env_file_path=$ #判断env.sh是否存在
function check_env_file() {
if [ -f ${env_file_path} ];then
echo "the ${env_file_path} is exist."
echo -e "\n\n"
else
echo "the ${env_file_path} is not exist."
exit
fi
} #生成nginx的location段的配置文件
function create_location(){
for pool in `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配置文件
function create_upstream_conf() {
for pool in `cat ${env_file_path} | cut -d "=" -f2 | cut -d ";" -f1 | sort | uniq`;do
ip_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} {"
for ip in ${ip_list[*]};do
echo -e "\tserver ${ip}:8080;"
done
echo "}"
done
} if [ $# -eq ];then
case $ in
location)
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}"
exit
esac
else
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脚本创建Nginx的upstream及location配置文件的更多相关文章

  1. Linux下添加shell脚本使得nginx日志每天定时切割压缩

    Linux下添加shell脚本使得nginx日志每天定时切割压缩一 简介 对于nginx的日志文件,特别是access日志,如果我们不做任何处理的话,最后这个文件将会变得非常庞大 这时,无论是出现异常 ...

  2. shell脚本分析nginx日志

    shell脚本分析nginx日志: name=`awk -F ',' '{print $13":"$32}' $file | awk -F ':' '{print $4}'`ech ...

  3. Shell脚本修改Nginx upstream配置文件

    #!/bin/bash ##################################################### # Name: change_nginx_upstream_conf ...

  4. 利用shell脚本实现nginx 的logs日志分割

    Nginx 是一个非常轻量的 Web 服务器,体积小.性能高.速度快等诸多优点.但不足的是也存在缺点,比如其产生的访问日志文件一直就是一个,不会自动地进行切割,如果访问量很大的话,将 导致日志文件容量 ...

  5. shell脚本备份nginx日志

    vim /data/runlog.sh                                                  #编辑一个 shell 脚本 #!/bin/bash LOGP ...

  6. shell脚本编写nginx部署脚本

    下面为shell脚本编写的nginx的安装及修改nginx.conf的脚本,脚本比较简单: #!/bin/bash function yum_install(){ yum install epel-r ...

  7. shell脚本之nginx的安装

           为了编写nginx自动部署的脚本而刚学习的shell脚本语言.写文章只是为了记录,有错误勿喷. 一.创建shell脚本程序        操作系统是Linux的 CentOS 7 版本. ...

  8. Linux下通过shell脚本创建账户

    当我们在linux平台上开发一些项目时,或者有一些项目是需要部署到linux系统上时,有时候会涉及到linux上的特定的账户,例如有一些项目需要运行在某些特定的账户下,或者有时候需要在全新的环境上搭建 ...

  9. Linux编程 20 shell编程(shell脚本创建,echo显示信息)

    一概述 前面19章里已经掌握了linux系统和命令行的基础知识,从本章开始继续学习shell脚本的基础知识.在大量编辑shell脚本前,先来学习下一些基本概念. 1.1    使用多个命令 Shell ...

随机推荐

  1. 取值:form表单取值、input框绑定取值

    1. form表单取值1.1 方式一,通过<form bindsubmit="formSubmit">与<button formType="submit ...

  2. Socket之简单的Unity3D聊天室__TCP协议

    服务器端程序 using System; using System.Collections.Generic; using System.Linq; using System.Net; using Sy ...

  3. 高级PHP工程师所应该具备的专业素养

    初次接触PHP,就为他的美所折服,于是一发不可收拾. 很多面试,很多人员能力要求都有“PHP高级工程师的字眼”,如果您真心喜欢PHP,并且您刚起步,那么我简单说说一个PHP高级工程师所应该具备的,希望 ...

  4. python函数之format

    自python2.6开始,新增了一种格式化字符串的函数str.format(),此函数可以快速处理各种字符串,它增强了字符串格式化的功能. 基本语法是通过{}和:来代替%.format函数可以接受不限 ...

  5. 【坚持】Selenium+Python学习之从读懂代码开始 DAY6

    2018/05/23 Python内置的@property装饰器 [@property](https://www.programiz.com/python-programming/property) ...

  6. Python 利用 BeautifulSoup 爬取网站获取新闻流

    0. 引言 介绍下 Python 用 Beautiful Soup 周期性爬取 xxx 网站获取新闻流: 图 1 项目介绍 1. 开发环境 Python: 3.6.3 BeautifulSoup:   ...

  7. centos7以上安装python3,一条命令搞定。

    直接复制下面的命令就搞定 yum install python34 python34-pip python34-setuptools 使用方法: python3 ---.py pip3 install ...

  8. Java 快排 排序

    一.快排的一种 ==================== public class myMain { public static void main(String[] args) { int t[] ...

  9. 【Ansible】ansible循环

    Ansible 循环 一.简单介绍 在ansible2.5之前,大多数人使”with_XXX”类型的关键字来操作循环,但是从2.6版本开始,官方推荐是”loop”关键字代替” with_XXX”. 1 ...

  10. Python参数传递,既不是传值也不是传引用

    面试的时候,有没有被问到Python传参是传引用还是传值这种问题?有没有听到过Python传参既不是传值也不是传引用这种说法?一个小小的参数默认值也可能让代码出现难以查找的bug? 如果你也遇到过上面 ...