有人告诉我,我可以使用grep
&sed
来查找和更改文件中的文本,但我的理解还不足以让它为我自己工作。
我有一个配置文件(lighttpd.conf)我需要添加一个新行:
server.modules += (
"mod_setenv"
)
setenv.add-response-header = ( "X-UA-Compatible" => "IE=edge",
"X-Frame-Options" => "Deny" )
setenv.add-environment = ("LC_ALL" => "en_US.UTF-8")
$HTTP["url"] =~ "config.js$" {
setenv.add-response-header = ( "Cache-Control" => "no-store, no-cache, must-revalidate, post-check=0, pre-check=0" )
}
ssl.cipher-list = "!aNULL:kECDH+AESGCM:ECDH+AESGCM:RSA+AESGCM:kECDH+AES:ECDH+AES:RSA+AES"
ssl.dh-file = "/etc/lighttpd/dhparams.pem"
$HTTP["url"] =~ "^/restapi" {
proxy.server = ( "" =>
((
"host" => "127.0.0.1",
"port" => "9202"
))
)
}
url.rewrite-if-not-file = ( "^/ui(?!\.\w+$)" => "/index.html",
"^/login" => "/index.html" )
server.stream-response-body = 2
#------HTTPPORT_CONFIG START------
#------HTTPPORT_CONFIG END------
我需要ssl.ca-file = "/etc/lighttpd/ca-cert.pem"
在该行后面添加ssl.dh-file = "/etc/lighttpd/dhparams.pem"
如下行:
ssl.cipher-list = "!aNULL:kECDH+AESGCM:ECDH+AESGCM:RSA+AESGCM:kECDH+AES:ECDH+AES:RSA+AES"
ssl.dh-file = "/etc/lighttpd/dhparams.pem"
ssl.ca-file = "/etc/lighttpd/ca-cert.pem"
$HTTP["url"] =~ "^/restapi" {
proxy.server = ( "" =>
我花了几个小时试图理解 RegEx,但我什至无法计算出定位 ssl.dh 文件行所需的字符串,更不用说如何在其后插入新行了。
如果有人能帮助我,我将非常感激。
答案1
我看到的唯一棘手的部分是您的模式和替换字符串包含正斜杠 - 因此为了避免必须转义它们,您需要设置不同的分隔符,例如%
sed ex。
sed '
\%^ssl.dh-file = "/etc/lighttpd/dhparams.pem"%a\
ssl.ca-file = "/etc/lighttpd/ca-cert.pem"
' lighttpd.conf