脚本添加删除nginx配置中的内容
2015-12-29 14:29
741 查看
[root@nodejs script]# more editnginx.sh #!/bin/bash # function back_check(){ # 备份配置和覆盖配置文件 cp -rf /etc/nginx/nginx.conf /etc/nginx/nginx.conf-$(date +%Y%m%d-%H%M%S) && \ echo "[+] /etc/nginx/nginx.conf-$(date +%Y%m%d-%H%M%S) backup OK!" # 对比修 diff nginx.conf /etc/nginx/nginx.conf # 覆盖线上配置 read -p "Write nginx config File(y/n)?" inString if [ $inString == "y" ];then cp -rf nginx.conf /etc/nginx/nginx.conf elif [ $inString == "n"];then echo "Quit!!!" exit 1 else echo "args error!!" exit 2 fi nginx -t -c /etc/nginx/nginx.conf } # 添加节点函数 function insert_row(){ # 编辑配置文件 nginx -t -c /etc/nginx/nginx.conf RETURN=$? if [ $RETURN == 0 ];then cp -rf /etc/nginx/nginx.conf nginx.conf && echo "[+] Copy nginx.conf to current directory OK!!" sed -i -n -e :a -e '1,2!{P;N;D;};N;ba' nginx.conf echo " location ~/api/v$1 { proxy_pass http://127.0.0.1:60$1; } } }" >>nginx.conf fi back_check } # 删除节点函数 function delete_row(){ cp -rf /etc/nginx/nginx.conf nginx.conf && echo "[+] Copy nginx.conf to current directory OK!!" sed -i "/location ~\/api\/v$1/,/}/d" nginx.conf back_check #sed -n "$1p" nginx.conf } # 帮助选项 function help(){ echo -e "Usage: $(basename $0) {-h|-i|-d}\n" } if [ -z $1 ];then help fi while getopts "i:d:h" OPTIONS; do case ${OPTIONS} in i ) insert_row $OPTARG;; d ) delete_row $OPTARG;; h ) help; exit;; esac done
# 添加
# 删除
相关文章推荐
- nginx upstream的分配方式
- [Nginx]多个域名绑定一个IP 的nginx设置
- ubuntu设置nginx为系统服务
- nginx
- nginx同时支持asp.net与php
- centos nginx 架设操作记录
- [备忘]Nginx 禁止IP访问及未绑定的域名跳转
- 【原】升级nginx注意点
- Nginx 的配置文件介绍
- 在Nginx服务器上安装配置博客程序Typecho的教程
- LNMP 1.2 Nginx编译安装
- nginx配置实现多组负载均衡
- nginx基于cookie粘滞做的负载均衡
- [置顶] ffmpeg rtmp推流 nginx搭建的rtmp服务器
- nginx 安装SSL
- nginx配置
- nginx+uwsgi+django整合部署
- Nginx/LVS/HAProxy负载均衡软件的优缺点详解
- nginx 安装
- 使用log_format为Nginx服务器设置更详细的日志格式