#!/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. Linux 技巧

    Linux Handbook For RedHat Enterprise Linux System System # clean old kernel packages package-cleanup ...

  2. 【日常训练】Help Chef Gerasim(Codeforces 99B)

    题意与分析 需要注意非法情况.换言之,合法情况其实很苛刻. 代码 /* * ACM Code => cf99b.java * Written by Sam X * Date: 三月, 19, 2 ...

  3. Post请求和Get请求;@RequestBody和@RequestParam

    1.@RequestBody用于Post请求,接收json数据,例如:@RequestBody User user 例如:@RequestBody Map map .不要用于Get请求. 2.@Req ...

  4. svn图文教程-宋正河整理

    下载地址:http://download.csdn.net/download/songzhengdong82/4433476 在线浏览:http://wenku.baidu.com/view/07f1 ...

  5. SNMP TRAP报文解析

    转载地址: https://blog.csdn.net/eric_sunah/article/details/19557683 SNMP的报文格式 SNMP代理和管理站通过SNMP协议中的标准消息进行 ...

  6. 微信小程序自定义 tabbar

    一定的需求情况下,无法使用小程序原生的 tabbar 的时候,需要自行实现一个和 tabbar 功能一模一样的自制组件. 查阅了海量的博客和文档之后,亲自踩坑.总结了三种在不使用微信小程序原生 tab ...

  7. Calico网络方案

    参考文档: Difficulties with traditional overlay networks:https://www.projectcalico.org/learn/ Get Start( ...

  8. word2vec的理解

    在学习LSTM的时候,了解了word2vec,简单的理解就是把词变成向量.看了很多书,也搜索了很多博客,大多数都是在word2vec的实现原理.数学公式,和一堆怎么样重新写一个word2vec的pyt ...

  9. tree命令详解

    基础命令学习目录首页 原文链接:http://man.linuxde.net/tree -a:显示所有文件和目录:-A:使用ASNI绘图字符显示树状图而非以ASCII字符组合:-C:在文件和目录清单加 ...

  10. PropertyGrid中的枚举显示为中文

    参考http://www.cnblogs.com/yank/archive/2011/09/17/2179598.html 在上述文档的基础上做了改进.从EnumConverter类派生 显示效果: ...