When you're writing an application to run on multiple domains, but using a single copy of code, the first thing you have to work out is your Web Server Configuration. Basically there will be a DNS entry for each domain pointed to your server's IP Address. Then your web server will have to be configured to handle those domains. Rarely, in an MSOC environment, will you need a separate site entry for each site you're serving, requiring one entry to serve all sites. If you're working with IIS on Windows you could just use the Default Web Site entry in your IIS manager. Apache is a little different.

If you followed along with the setup posts on setting up your environment for multi-instance, you created several VirtualHost entries to point different domains to different instances of ColdFusion. The path you choose next depends on two things: 1) Will you ever serve another domain on this system served by different code? And 2) are each of your domains entirely unique? Or are the just subdomains of the same root domain? (These questions are relevant on Windows as well, and treated similarly)

Let's say that all of your sites will be subdomains of the same root domain. This configuration gets pretty simple, as all you'd need to do is setup another VirtualHost entry.

view plain print about
1# Setup - MultiHome Instance
2<VirtualHost *:80>
3 ServerName primary.multihome.loc
4 ServerAlias *.multihome.loc
5 # The next include file contains the entries for the
6 # ColdFusion instance to use with these sites
7 Include conf/extra/multihome_CF.conf
8 DocumentRoot "C:/Inetpub/wwwroot/multihome"
9 <Directory "C:/Inetpub/wwwroot/multihome">
10 Options Indexes FollowSymLinks MultiViews ExecCGI
11 AllowOverride All
12 Order allow,deny
13 Allow from all
14 </Directory>
15 DirectoryIndex index.cfm index.html
16 ServerAdmin web.admin@mydomain.com
17 ErrorLog "multihome.loc-error.log"
18 CustomLog "multihome.loc-access.log" common

After that the 'multihome' directory would be the root directory for every site using the 'multihome.loc' root domain. This is accomplished through the 'ServerAlias' attribute of your VirtualHost configuration.

Now let's say that you're using many different domain names, or that maybe you will also run some other sites on the server as well (not recommended). In this scenario, like IIS, you'll need to run these sites off the default site configuration. As I mentioned before, on IIS this means configuring the Default Web Site entry. Apache has something very similar.

Have you ever really read the httpd.conf file from your Apache install? The entire document is loads upon loads of comments, giving you instructions on what different declaration blocks and attributes do. If you were to strip out all of your comments from the file, it would most likely look something like this:

view plain print about
1ServerRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2"
3Listen 80
5LoadModule actions_module modules/mod_actions.so
6LoadModule alias_module modules/mod_alias.so
7LoadModule asis_module modules/mod_asis.so
8LoadModule auth_basic_module modules/mod_auth_basic.so
9LoadModule authn_default_module modules/mod_authn_default.so
10LoadModule authn_file_module modules/mod_authn_file.so
11LoadModule authz_default_module modules/mod_authz_default.so
12LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
13LoadModule authz_host_module modules/mod_authz_host.so
14LoadModule authz_user_module modules/mod_authz_user.so
15LoadModule autoindex_module modules/mod_autoindex.so
16LoadModule cgi_module modules/mod_cgi.so
17LoadModule dir_module modules/mod_dir.so
18LoadModule env_module modules/mod_env.so
19LoadModule include_module modules/mod_include.so
20LoadModule isapi_module modules/mod_isapi.so
21LoadModule log_config_module modules/mod_log_config.so
22LoadModule mime_module modules/mod_mime.so
23LoadModule negotiation_module modules/mod_negotiation.so
24LoadModule setenvif_module modules/mod_setenvif.so
25LoadModule vhost_alias_module modules/mod_vhost_alias.so
27<IfModule !mpm_netware_module>
28    <IfModule !mpm_winnt_module>
29        User daemon
30        Group daemon
31    </IfModule>
34ServerAdmin web.admin@mydomain.com
36DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
38<Directory />
39 Options FollowSymLinks
40 AllowOverride None
41 Order deny,allow
42 Deny from all
45<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
46 Options Indexes FollowSymLinks
47 AllowOverride None
48 Order allow,deny
49 Allow from all
52<IfModule dir_module>
53 DirectoryIndex index.html
56<FilesMatch "^\.ht">
57 Order allow,deny
58 Deny from all
59 Satisfy All
62ErrorLog "logs/error.log"
64LogLevel warn
66<IfModule log_config_module>
67 LogFormat "%h %l %u %t \"%r\" %>
s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
68 LogFormat "%h %l %u %t \"%r\" %>s %b" common
69 <IfModule logio_module>
70 # You need to enable mod_logio.c to use %I and %O
71 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
72 </IfModule>
73 CustomLog "logs/access.log" common
76<IfModule alias_module>
77 ScriptAlias /cgi-bin/ "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/"
80<IfModule cgid_module>
83<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin">
84 AllowOverride None
85 Options None
86 Order allow,deny
87 Allow from all
90DefaultType text/plain
92<IfModule mime_module>
93 TypesConfig conf/mime.types
94 AddType application/x-compress .Z
95    AddType application/vnd.adobe.air-application-installer-package+zip .air
96 AddType application/x-gzip .gz .tgz
99<IfModule ssl_module>
100    SSLRandomSeed startup builtin
101    SSLRandomSeed connect builtin
104LoadModule jrun_module "C:/JRun4/lib/wsconfig/1/mod_jrun22.so"
105<IfModule mod_jrun22.c>
106 JRunConfig Verbose false
107 JRunConfig Apialloc false
108 JRunConfig Ignoresuffixmap false
109 JRunConfig Serverstore "C:/JRun4/lib/wsconfig/1/jrunserver.store"
110 JRunConfig Bootstrap # Default ColdFusion instance port
111 AddHandler jrun-handler .jsp .jws .cfm .cfml .cfc .cfr .cfswf
114Include conf/extra/httpd-vhosts.conf
116<Files ~ ".hbmxml$">
117Order allow,deny
118Deny from all

What you might not realize is that these settings control the 'default' web site for Apache. If DNS for a domain is pointed to your server, and a VirtualHost declaration does not exist for that domain, then these settings will control that requested site. These are the defaults used by all sites on the system (VirtualHosts and otherwise). VirtualHost declarations override these settings on a per domain basis. I am not an expert on Apache, in any way, so you will have to carefully review these settings to determine what is necessary, and what should be stricken for your own server's protection. To point these undeclared sites to your MSOC codebase, the only true change needed is to change the DocumentRoot declaration to point to the 'multihome' folder, and ensure that the JRunConfig Bootstrap attribute is pointed to the port of the ColdFusion instance you intend to use for your sites.

Using the Default Web Site of your web server is the 'easy way' of handling configuration, as you do it once and control it in a single location. This will not work in all situations. You may want much more granular control, like unique ISAPI rewrites per domain, which would require you to have and maintain individual site entries in your configurations. Whatever method you choose, please take the time to research what is necessary to 'harden' your server against possible intrusion.

Our next MSOC post, we'll begin to get into initial application configuration and discuss file structure. As always, if you have an comments, questions, suggestions, or general feedback, feel free to comment on this post, or contact me through the link at the bottom of this screen.