【发布时间】:2015-01-05 11:03:27
【问题描述】:
我正在尝试使用 sed 编辑 aws elasticbeanstalk nginx 配置文件。我想在默认位置块之后插入一个新的位置块。
为此,我要匹配上一个位置块中的一行,然后我想跳过 8 行,然后插入文本。
这是我运行 sed 之前的样子
upstream nodejs {
server 127.0.0.1:8081;
keepalive 256;
}
server {
listen 8080;
location / {
proxy_pass http://nodejs;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
这是我构建命令的天真尝试,它实际上不起作用,而是将新块粘贴在包含 proxy_pass http://nodejs; 的行下。
sed -i '/nodejs;/a \ location ^~ /blog {}' /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
如何跳过我在regex 中标识的行之后的 8 行。此外,还建议以另一种方式确定我想在哪里放置我的新块。
【问题讨论】:
-
你能发布新配置的样子吗?
-
您能否依赖该位置下方
}的缩进。还是最后的}?我认为像awk这样更高级的东西可能更适合这项任务。
标签: regex bash nginx sed amazon-elastic-beanstalk