CFMX Multi Instance Apache config - made simple

If the title makes sense then the rest of the article will be a breeze.

For some the hardest part of Apache is the fact that there is no GUI (Graphical User Interface) for the configuration. To me it's the reason I love apache! While it might be a bit daunting if you are new to Apache the power and flexibility that the text file configuration gives you is simply not feasible in an GUI.

At RedBalloon we have a number of different sites and a number of different servers so being able to manage the config files and lay them out to suit our needs it a huge boost. On top of this, we version our config files using subversion which gives us backups, rollback and a version history.

The windows installer sets up a basic and very well commented config which is a great base to start from. We typically add the following line at the end to allow simple loading of the virtual host config files:

Include cont/vhost/*.conf

Each vhost file consists of a number of related virtual host sections:

Listen 127.0.0.1:80
Listen 127.0.0.1:443

NameVirtualHost 127.0.0.1:80
NameVirtualHost 127.0.0.1:443
#Site 1
<VirtualHost 127.0.0.1:80> #HTTP
   <-- removed for clarity -->
</VirtualHost>
<VirtualHost 127.0.0.1:443> # HTTPS
   <-- removed for clarity -->
</VirtualHost>
#Site 2
<VirtualHost 127.0.0.1:80>
   <-- removed for clarity -->
</VirtualHost>
<VirtualHost 127.0.0.1:443>
   <-- removed for clarity -->
</VirtualHost>

We deliberately add listen directives at the top of the vhost file to easy migration of sites from one machine to another. All settings for a particular site are in one spot.

The sites in any one file are all related - i.e. for redballoon we have the main consumer site, our suppliers extranet site etc all in the one config.

The inner sections of the virtual host looks as follows:

<VirtualHost 127.0.0.1:80>
Include conf/cfinstance/example1-instance.conf

DocumentRoot /path/to/wwwroot
ServerName www.example.com

Include conf/aliases/example1-aliases.conf
</VirtualHost>
<VirtualHost 127.0.0.1:443>
Include conf/cfinstance/example1-instance.conf
Include conf/ssl/example1-ssl.conf

DocumentRoot /path/to/wwwroot
ServerName www.example.com

Include conf/aliases/example1-aliases.conf
</VirtualHost>

By moving all of the common/repeated lines out to well named include files the vhost section is very simple to read and understand. It also makes it easy to add an alias across common sites or change the cfinstance the website is using.

Each of the include files is just the lines that would be directly in the file pulled out to an external file.

Eg - the cfinstance/example1-instance

JRunConfig Serverstore /opt/jrun4/lib/wsconfig/1/jrunserver.store
# Bootstrap port is what specifies which instance to be used - see the JRun admin for the relevant numbers
JRunConfig Bootstrap 127.0.0.1:51020
JRunConfig Apialloc false

Gotchas

SSL certificates

If you are using SSL sites with name based virtual hosting there is a limitation which is: You can only have one SSL certificate - This works fine if all the sites are under the same domain - i.e. site1.example.com & site2.example.com and you have a wildcard certificate - *.example.com. The reason for this limitation is that when the server sends the SSL cert it doesn't yet know which domain you are looking for as it happens at the negotiation phase. Once the SSL cert is in use though the request proceeds correctly and serves the correct site.

Wildcard sites - *.example.com

Apache supports the * operator for sites which mean any subdomain site will match this virtual host. With name based virtual hosting only the first site on a particular IP address will be able to do this. So it wouldn't work to have *.example1.com and *.example2.com on the same IP address. To get around this you need seperate IP addresses for each group of sites.

Conclusion

Apache configs are not as scary as you think - and the documentation is great. They allow you loads of control of the server, are easy to backup and can be used with version control and can be edited with any editor of choice.

Comments
kisy's Gravatar The reason for this limitation is that when the server sends the SSL cert it doesn't yet know which domain you are looking for as it happens at http://www.batteryfast.com/toshiba/satellite-5000.... toshiba satellite 5000 battery,
http://www.batteryfast.com/toshiba/portege-a100.ht... toshiba portege a100 battery,
http://www.batteryfast.com/toshiba/satellite-5100.... toshiba satellite 5100 battery,
http://www.batteryfast.com/toshiba/pa3128u.htm toshiba pa3128u battery,
http://www.batteryfast.com/toshiba/pa3191u.htm toshiba pa3191u battery,
http://www.batteryfast.com/toshiba/portege-4000.ht... toshiba portege 4000 battery,
http://www.batteryfast.com/toshiba/portege-m200.ht... toshiba portege m200 battery,
http://www.batteryfast.com/toshiba/portege-m205.ht... toshiba portege m205 battery,
http://www.batteryfast.com/toshiba/portege-m400.ht... toshiba portege m400 battery,

http://www.batteryfast.com/toshiba/pa3209u.htm toshiba pa3209u battery,
http://www.batteryfast.com/toshiba/satellite-1100.... toshiba satellite 1100 battery,
http://www.batteryfast.com/toshiba/satellite-1110.... toshiba satellite 1110 battery,
http://www.batteryfast.com/toshiba/pa3399u-1bas.ht... toshiba pa3399u-1bas battery,
http://www.batteryfast.com/toshiba/satellite-a100.... toshiba satellite a100 battery,
http://www.batteryfast.com/toshiba/satellite-a105.... toshiba satellite a105 battery,
http://www.batteryfast.com/toshiba/satellite-a80.h... toshiba satellite a80 battery,
http://www.batteryfast.com/toshiba/satellite-m100.... toshiba satellite m100 battery,
http://www.batteryfast.com/toshiba/satellite-m105.... toshiba satellite m105 battery,

http://www.batteryfast.com/toshiba/satellite-m110.... toshiba satellite m110 battery,
http://www.batteryfast.com/toshiba/satellite-m115.... toshiba satellite m115 battery,
http://www.batteryfast.com/toshiba/satellite-m40.h... toshiba satellite m40 battery,
http://www.batteryfast.com/toshiba/satellite-m45.h... toshiba satellite m45 battery,
http://www.batteryfast.com/toshiba/satellite-m50.h... toshiba satellite m50 battery,
http://www.batteryfast.com/toshiba/satellite-m55.h... toshiba satellite m55 battery,
http://www.batteryfast.com/toshiba/pa3356u.htm toshiba pa3356u battery,
http://www.batteryfast.com/toshiba/a50.htm toshiba a50 battery,
http://www.batteryfast.com/toshiba/a55.htm toshiba a55 battery,
the negotiation phase. Once the SSL cert is in use though the request proceeds correctly and serves the correct site.
# Posted By kisy | 9/28/08 2:25 PM
warhammer gold's Gravatar CFMX Multi Instance Apache config - made simple
# Posted By warhammer gold | 10/9/08 7:24 PM
directoy's Gravatar I'm loving AJAXCFC, really good work you've done here.
it's turning out to be pretty nice. anyways, just wanted to say thanks for sharing.I just started on my personal site (http://www.qxiu.net) using AJAXCFC along with the Flickr API,
# Posted By directoy | 10/15/08 5:06 PM
fdghhhgh's Gravatar nissan cars
http://usednissanpathfinder.blogspot.com/   used nissan pathfinder
# Posted By fdghhhgh | 10/21/08 8:04 PM
warhammer gold's Gravatar <A href="http://www.vipwarhammergold.com/" target=_blank><FONT =4><B>warhammer gold</B></FONT></A> <FONT =4></FONT><A href="http://www.vipwarhammergold.com/news/news.html" target=_blank><FONT size=4><B>buy warhammer gold</B></FONT></A><BR><A href="http://www.bestwarhammer.com/" target=_blank><FONT size=4><B>warhammer gold</B></FONT></A><FONT size=4></FONT> <A href="http://www.bestwarhammer.com/news/news.html" target=_blank><FONT size=4><B>buy warhammer gold</B></FONT></A><BR><A href="http://www.aocsale.com/" target=_blank><FONT size=4><B>aoc gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.aocsale.com/aoc-news/" target="_blank">http://www.aocsale.com/aoc-news/" target=_blank><FONT size=4><B>age of conan gold</B></FONT></A><BR><A href="http://www.game4power.com/" target=_blank><FONT size=4><B>wow gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.game4power.com/news/" target="_blank">http://www.game4power.com/news/" target=_blank><FONT size=4><B>buy wow gold</B></FONT></A><BR><A href="http://www.wowgoldone.com/" target=_blank><FONT size=4><B>wow gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.wowgoldone.com/" target=_blank><FONT size=4><B>buy wow gold</B></FONT></A><BR><A href="http://www.game4power.com/" target=_blank><FONT size=4><B>world of warcraft gold</B></FONT></A> <FONT size=4></FONT><A href="http://www.wowgoldone.com/" target=_blank><FONT size=4><B>world of warcraft gold</B></FONT></A><BR><A href="http://www.gamelevelup.com/" target=_blank><FONT size=4><B>wow power leveling</B></FONT></A><BR><A href="http://itemstores.com/" target=_blank><FONT size=4><B>wow item</B></FONT></A>
# Posted By warhammer gold | 11/18/08 4:18 PM