如何在 shell 脚本中修改配置文件?取消某些注释 / 修改些值什么的?

发布于 2021-11-03 10:01:24 字数 835 浏览 816 评论 4

我在 CentOS 下,想要编写一个 Shell 脚本修改 Nginx 的配置文件 nginx.conf,做如下修改:

1、取消下面行的程序注释

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ .php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

2、把其中的

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

修改为

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

请问如何在 Shell 脚本中通过编程实现?谢谢!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

妖妓 2021-11-08 05:38:38

谢谢!能稍微解释一下么?看不太懂,呵呵。

浅沫记忆 2021-11-08 00:08:08

就是在含有 .php$ 字符的一行前面插入一段内容

无法言说的痛 2021-11-07 06:47:52

哦,我知道了!谢谢!

猫烠⑼条掵仅有一顆心 2021-11-06 04:06:48
sed '/.php$/i location ~ .php$ {n    root           html;n    fastcgi_pass   127.0.0.1:9000;n    fastcgi_index  index.php;n    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;n    include        fastcgi_params;n}' nginx.conf

 

opadmin@discuz:~/temp$ sed '/.php$/i location ~ .php$ {n    root           html;n    fastcgi_pass   127.0.0.1:9000;n    fastcgi_index  index.php;n    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;n    include        fastcgi_params;n}' aaa.txt
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}
#location ~ .php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文