#!/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. How to: Display a Non-Persistent Object's List View from the Navigation

    This example demonstrates how to display a non-persistent object's List View when a navigation item ...

  2. Bitcoin区块链攻击方式

    目录 重放攻击-- 非人为攻击 其他攻击 重放攻击-- 非人为攻击 重放攻击 Replay Attach 攻击者重复发送相同的数据库包到目的主机,用以欺骗系统 用支付宝付款信息重复项商家索取商品 比特 ...

  3. pdo的用处,用法

    PDO主要是用来对数据库进行访问的.PDO扩展为PHP访问数据库定义了一个轻量级的一致接口,不同数据库在访问时,采用相同方法名称,解决了连接数据库不统一问题.PDO扩展自身并不能实现任何数据库功能,必 ...

  4. netbeans 类重复 解决

    Help -> About -> Cache directory 记录Cache directory目录 删除该目录下的所有文件 重启

  5. 特效Shader对雾的处理

    RFX4_Particle.shader案例 #ifdef BlendAdd UNITY_APPLY_FOG_COLOR(i.fogCoord, res, half4(0,0,0,0)); #endi ...

  6. AI入门课程资源

    企业 kaggle https://www.kaggle.com/learn/overview Google   介绍 https://developers.google.cn/machine-lea ...

  7. nodejs 中jead模板改为ejs

    var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set(' ...

  8. 简单理解DNS解析流程(一)

    0x0 简单理解dns DNS服务器里存着一张表 表中放着域名和IP地址,域名和IP地址以映射关系保存,即一对一 浏览器访问某个域名,实际上是访问它的ip地址 所以浏览器需要知道域名对应的ip地址 如 ...

  9. Linux下端口映射工具rinetd

    Linux下简单好用的工具rinetd,实现端口映射/转发/重定向官网地址http://www.boutell.com/rinetd 软件下载wget http://www.boutell.com/r ...

  10. unzip/tar命令详解

    博客目录总纲首页 原文链接:https://www.cnblogs.com/zdz8207/p/3765604.html Linux下的压缩解压缩命令详解及实例 实例:压缩服务器上当前目录的内容为xx ...