#!/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. MVC Redirect 页面跳转不了

    1:如果是AJAX调取后台控制器的方法,那么最后跳转的步骤应该在AJAX的success方法里面执行跳转 若果要在控制器跳转那么 应该是前端页面 进行表单提交 在控制器直接用 redire等跳转方法

  2. IIS 配置网站

    IIS 配置网站最常见的问题 1 文件夹权限问题 (C盘 windows下temp文件夹权限问题)2 版本问题 (框架版本问题如4.0 在2.0下运行,4.5在4.0下运行) 3如果是局域网,考虑动态 ...

  3. 开源项目CIIP(企业信息管理系统框架).2018.0904版更新介绍

    源码: https://github.com/tylike/CIIP https://gitee.com/ciip/CIIP 一,CIIP的目标是什么? 更加简单,快速的建立信息类管理系统.让实施人员 ...

  4. Frida----基本代码

    代码来自官网:https://www.frida.re/docs/examples/android/ import frida, sys def on_message(message, data): ...

  5. Java线程wait和sleep的区别

    Java中调用wait方法或者sleep方法都可以让线程进入waitint或者time-waiting状态,但是它们还是 有所不同的: wait是Object中的方法,而sleep则是Thread中的 ...

  6. 【LeetCode算法题库】Day3:Reverse Integer & String to Integer (atoi) & Palindrome Number

    [Q7]  把数倒过来 Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Outpu ...

  7. python-五行红旗实现

    import turtle """ 绘制五星红旗 作者:zxj 版本:1.0 """ # 绘制矩形函数 def giant(leg,hig) ...

  8. (转)Django配置数据库读写分离

    转:https://blog.csdn.net/Ayhan_huang/article/details/78784486 转:http://www.cnblogs.com/dreamer-fish/p ...

  9. Final阶段中间产物

    空天猎功能说明书:https://git.coding.net/liusx0303/Plane.git 空天猎代码控制:https://coding.net/u/MR__Chen/p/SkyHunte ...

  10. bootstrap table的展开行问题

    照着网上与api里说的添加detailView属性设置为true,detailFormatter属性为展开后的内容,但是设置之后发现,在表格每一行最前面是多出一列正常该显示"+"的 ...