-1

I have a httpd.conf file containing the following virtual hosts :

<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>

I want to insert the following lines only for VirtualHost *:443 :

<Proxy *>
Require all granted
</Proxy>
ProxyPass /App https://servername:8080/App/
ProxyPassReverse /App https://servername:8080/App/

I had a lot of tries but could not find the proper 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

With GNU sed and GNU bash:

Put new lines in a file (insert.txt).

sed '/^<VirtualHost \*:443>/r insert.txt' httpd.conf

or use stdin:

echo -e 'lines\nto\ninsert' | sed '/^<VirtualHost \*:443>/r /dev/stdin' httpd.conf

If you want to edit your httpd.conf "in place" use sed's option -i.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.