Any suggestions on how to simplify my httpd.conf file? I've stripped out everything but the relevant portions:

Listen <ip-addr-1>:80
Listen <ip-addr-1>:443

<VirtualHost <ip-addr-1>:80>
ServerName myservername.com

<Proxy balancer://mycluster>
BalancerMember http://172.22.22.20
BalancerMember http://172.22.22.21
</Proxy>

ProxyPass /app1 balancer://mycluster/app1
ProxyPassReverse /app1 balancer://mycluster/app1
</VirtualHost>

# Repeat for 443
<VirtualHost <ip-addr-1>:443>
ServerName myservername.com

SSLEngine On
SSLCertificateFile      conf/ssl/mycert.crt
SSLCertificateKeyFile   conf/ssl/mycert.key
SSLCACertificateFile    conf/ssl/intermediate.crt

<Proxy balancer://mycluster>
BalancerMember http://172.22.22.20
BalancerMember http://172.22.22.21
</Proxy>

ProxyPass /app1 balancer://mycluster/app1
ProxyPassReverse /app1 balancer://mycluster/app1
</VirtualHost>

Is there anyway to not repeat everything for port 80 and 443, but turn on ssl for 443?

link|improve this question

75% accept rate
feedback

2 Answers

up vote 1 down vote accepted

You could use an include if you're concerned about the editability - just move the repeated part to a separate file, say balancer.cfg and then Include balancer.cfg.

If your aim is to have a single Virtual Host definition I reckon that's not possible in this case. If you had multiple ports speaking HTTP you could just use VirtualHost 10.1.2.3:* and it would match every port, or use a list like VirtualHost 10.1.2.3:80 10.1.2.3:81 and so on. But in this case I don't see a way to serve both HTTP and HTTPS using the same definition - only one can match, it would seem, so the one being matched should contain the complete configuration.

Apache selects the best match only on the basis of the IP address (or wildcard) and port number. If there are multiple identical best matches, the first VirtualHost appearing in the configuration file will be selected.

http://httpd.apache.org/docs/current/vhosts/details.html

link|improve this answer
Thank you. Includes should work pretty well for what I need. – TestPlanManagement.com May 1 '11 at 17:55
feedback

I think I can do a touch better:

Listen 80
Listen 443

ServerName myservername.com
ProxyPass /app1 balancer://mycluster/app1
ProxyPassReverse /app1 balancer://mycluster/app1

SSLCertificateFile      conf/ssl/mycert.crt
SSLCertificateKeyFile   conf/ssl/mycert.key
SSLCACertificateFile    conf/ssl/intermediate.crt

<Proxy balancer://mycluster>
    BalancerMember http://172.22.22.20
    BalancerMember http://172.22.22.21
</Proxy>

<VirtualHost *:80>
</VirtualHost>

# Repeat for 443
<VirtualHost *:443>
    SSLEngine On
</VirtualHost>

I confess that I don't know whether the VirtualHost directive for *:80 can be entirely omitted, but based on the Apache docs, this much should work.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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