다음 가상 호스트를 포함하는 httpd.conf 파일이 있습니다.
<VirtualHost *:443>
JkMount /soncn/* tomcat3
SSLProtocol -all +TLSv1
SSLCipherSuite RSA:!LOW:!EXP:!eNULL:!aNULL:!RC4
SSLEngine on
SSLCertificateFile bla
SSLCertificateKeyFile bla
RewriteEngine On
RewriteOptions Inherit
ServerName dionisos
</VirtualHost>
SSLSessionCache dbm:/opt/apache/logs/ssl_gcache_data
<VirtualHost *:8443>
SSLProtocol -all +TLSv1
SSLCipherSuite RSA:!LOW:!EXP:!eNULL:!aNULL:!RC4
SSLEngine on
SSLCertificateFile bla
SSLCertificateKeyFile bla
RewriteEngine On
RewriteOptions Inherit
ServerName dionisos
ProxyRequests Off
ProxyPreserveHost On
PerlModule CSA_Filter
<Proxy *>
Require all granted
</Proxy>
ProxyPass / ajp://162.237.187.150:8012/
ProxyPassReverse / ajp://162.237.185.150:8012/
ProxyTimeout 3600
</VirtualHost>
<VirtualHost *:8191>
SSLProtocol -all +TLSv1
SSLCipherSuite RSA:!LOW:!EXP:!eNULL:!aNULL:!RC4
SSLEngine on
SSLCertificateFile bla
SSLCertificateKeyFile bla
RewriteEngine On
RewriteOptions Inherit
ServerName dionisos
ProxyRequests Off
ProxyPreserveHost On
PerlModule CSA_Filter
<Proxy *>
Require all granted
</Proxy>
ProxyPass / ajp://bla:8010/
ProxyPassReverse / ajp://bla:8010/
ProxyTimeout 3600
</VirtualHost>
VirtualHost *:443에 대해 다음 줄을 삽입하고 싶습니다.
<Proxy *>
Require all granted
</Proxy>
ProxyPass /App https://servername:8080/App/
ProxyPassReverse /App https://servername:8080/App/
많이 시도했지만 적합한 sed를 찾을 수 없습니다.
cat httpd.conf|tr '\n' '^'|sed 's#\(<VirtualHost \*:443>.*ServerName dionisos\)#\1 \n<Proxy *>\nRequire all granted\n</Proxy>\nProxyPass /App https://servername:8080/App/\nProxyPassReverse /Wibox https://servername:8080/App/ \n#g'|tr '^' '\n' > httpd.conf.updated
답변1
GNU sed 및 GNU bash 사용:
파일(insert.txt)에 새 줄을 추가합니다.
sed '/^<VirtualHost \*:443>/r insert.txt' httpd.conf
또는 표준 입력을 사용하십시오.
echo -e 'lines\nto\ninsert' | sed '/^<VirtualHost \*:443>/r /dev/stdin' httpd.conf
httpd.conf를 "제자리에서" 편집하려면 sed의 options 을 사용하십시오 -i
.