Welcome Guest | Login

VirtualHosts, Parked Domains, Subdomains, Addon Domains, and Symlinking

Greetings everyone, I hope this short article will help clear the air on parked, addon, and subdomains and how you can most effectively host multiple sites (Rails or Non-Rails) with your HostingRails.com account:


-----------------------------
The Fresh VirtualHost Entry
-----------------------------


Let's first learn the basics about how an Apache VirtualHost entry is setup.  This is very important for you to understand.  Let's say, for example, you signed up with your-full-name-temp.com on a shared IP and wanted to make use of our "Sneak Peek" domain feature.  The first few relevant lines we'd setup for you would be this:  
<VirtualHost Shared_IP_Address-->
ServerAlias your-full-name-temp.com
DocumentRoot /home/username/public_html
ServerName www.your-full-name-temp.com
ServerAlias 234user.hostname.hostingrails.com www.234user.hostname.hostingrails.com
...

-----------------------------
The Parked Domain
-----------------------------


Can you spot what the parked domain for this account is?  

That's right! If you pointed your browser to 234user.hostname.hostingrails.com it would serve up the files located at /home/username/public_html

When you create a 'Parked Domain' via cPanel, it simply adds a ServerAlias to the VirtualHost entry for the target domain.  Thus, in the above example, 234user.hostname.hostingrails.com is said to be "parked over" your-full-name-temp.com  

You can add as many parked domains as you want, which is useful for single applications like Mephisto than can handle multiple domains.  


-----------------------------
The Subdomain
-----------------------------


When you create a subdomain in cPanel, you are creating a new VirtualHost entry:
<VirtualHost Shared_IP_Address-->
ServerAlias subdomain.your-full-name-temp.com
DocumentRoot /home/username/public_html/subdomain
ServerName www.subdomain.your-full-name-temp.com
...
Thus, browsing to subdomain.your-full-name-temp.com, assuming you have it pointing to the server by now, will bring you to the files in /home/username/public_html/subdomain - if you don't have this domain pointing to the server (afterall it is a temp domain) then you can just create a parked domain over it; the parked domain should already be pointing at the server/IP for this to work)


-----------------------------
The Addon Domain
-----------------------------


cPanel is smart with addon domains.  These are "fully hosted" domains in every sense, as you can have mail, databases, etc... for this domain only - however the VirtualHost entry the addon domains is technically a domain parked over a subdomain:

<VirtualHost Shared_IP_Address-->
ServerAlias addondomain.your-full-name-temp.com
DocumentRoot /home/username/public_html/addondomain
ServerName www.addondomain.your-full-name-temp.com
ServerAlias addondomain.com www.addondomain.com
...
Thus, browsing to addondomain.com will bring you to the contents of /home/username/public_html/addondomain - even if your-full-name-temp.com is still a bogus domain.



-----------------------------
The Art of Symlinking
-----------------------------


So here's where the beauty, ease, and flexibility of symlinking comes in.  You should create all your Rails apps or non-rails websites in your root [~]

Since most people learn best by example, I'll walk you through the process of setting up two addon domains (one rails, one static) and a subdomain over an account that I signed up for with your-full-name-temp.com

- - -

Lets say in my root I have this:
addon1_rails
addon2_static
public_html
subdomain_rails
In cPanel I would go addon my domain1.com, whose DocumentRoot would be /home/username/public_html/domain1

So to get this domain working I just remove that 'domain1' folder cPanel created and make a symlink
username@hostname [~]# cd public_html
username@hostname [~/public_html]# rm -rf domain1
username@hostname [~/public_html]# ln -s ~/addon1_rails/public ~/public_html/domain1
And that's it - browsing to domain1.com will get me my Rails app.  This works even if your main domain is already an existing Rails app.  

- -

For the addon2_static website the process is essentially the same:

In cPanel I would go addon my domain2.com, whose DocumentRoot would be /home/username/public_html/domain2

So to get this domain working I just remove that 'domain2' folder cPanel created and make a symlink
username@hostname [~]# cd public_html
username@hostname [~/public_html]# rm -rf domain2
username@hostname [~/public_html]# ln -s ~/addon2_static ~/public_html/domain2
And that's it - browsing to domain2.com will get me my static website.  This, again, also works even if your main domain is already an existing Rails app.  

- -

For the subdomain_rails website the process is also essentially the same:

In cPanel I would go create my subdomain, whose DocumentRoot would be /home/username/public_html/subdomain

So to get this subdomain working I just remove that 'subdomain' folder cPanel created and make a symlink
username@hostname [~]# cd public_html
username@hostname [~/public_html]# rm -rf subdomain
username@hostname [~/public_html]# ln -s ~/subdomain_rails/public ~/public_html/subdomain
And that's it - browsing to the subdomain will get me my static website.  This, again, also works even if your main domain is already an existing Rails app.



-----------------------------
Summary
-----------------------------


Essentially - create all your apps and website in folder in your root.  Create addon domains and subdomains if you want the DocumentRoot to be different (i.e. if you want them pointing to different folders) - and create a parked domain if you want a domain to point to the same location as another domain.  All the magic then happens with the symlink as described above.  And you can imagine how helpful this is if you want to setup a test domain and just work the symlinks, or move an app quickly to another domain, etc...

Questions?  Corrections?  I will update this post as necessary, thanks in advance for your input.    

Cheers,

~William

2007-01-17 09:54 PM

MN MLS - Buy/Sell Real Estate in Minnesota
That's a very useful post. Thanks.

I've just have a couple of questions:

In the example of adding domain2 as an addon domain, should the line
username@hostname [~/public_html]# ln -s ~/addon2_static ~/public_html/domain1
be

username@hostname [~/public_html]# ln -s ~/addon2_static ~/public_html/domain2
Also, shouldn't the `rm` commands you give be either `rmdir` or `rm -rf`? Vanilla rm won't work on directories.

One issue I don't think was addressed in the above explanation was how to direct your original domain "your-full-name-temp.com" to a subdirectory of public_html.

If I've understood what you've written properly, the symlinks for the subdomain and addon domain live inside the public_html folder.

I'm in a situation where I want my first domain your-full-name-temp.com to be a rails app, let's call it app1. To do this I believe that I remove the original public_html directory and create a symlink
# ln -s ~/app1/public ~/public_html
Now all of my subdomains and addon symlinks will live inside ~/public_html as before. But this is actually ~/app1/public.

I'd rather keep my sites and apps all completely separate if possible so is there some way of avoiding having the subdomain and addon symlinks in my app1/public directory?

2007-02-03 08:55 PM

Hi there - you've done the right thing with your symlinks.  There is unfortunately no way to prevent the addon symlinks from residing in your public_html dir (app1/public) - since these are all symlinks of course there is no functional problem, but I agree that it would be cleaner to have them completely seperate.  

This is a [limitation? Security Feature?] of cPanel automatically placing the DocumentRoot of the subdomains within public_html - if you'd like your DocumentRoots manually changed please feel free to email us at support and we'll take care of it.  

Thanks for the corrections, I've added them in.  'Much appreciated.

~William


2007-02-04 05:45 PM

MN MLS - Buy/Sell Real Estate in Minnesota
I think I may have answered my own question below.  I'll leave it here in case it helps anyone else.

/// orig question
What is the best way make secure.mydomain.com point to the same exact directory as mydomain.com?

I purchased an ssl cert w/ the 'secure' word.  All I want to do is instill purchaser confidence when they see that url name...I have all the files I need in the current rails app reachable by mydomain.com.

Excellent article, btw.

//// (maybe) answer

I was initially confused by William's conclusion, since it seemed my need didn't match the 3 scenarios.

Here's what I did...please tell me if this is not the best way.

I created a subdomain in cpanel (secure.mydomain.com).

I then went into my public domain and:

rm -Rf secure
ln -s . secure

now browsing to secure.mydomain.com takes me to the same directory as mydomain.com via symlink.

One question though about subdomains:  When I create a subdomain, is there actually DNS info that needs to get propogated before that works?


2007-03-31 10:41 PM

Hi Jsquires,

Welcome to the forums.

If you point secure.mydomain.com to mydomain.com, your visitors will receive a security warning when they open the secure page. The warning will be something similar to:

"- The server's name "mydomain.com" does not match the certificate's name "ecure.mydomain.com". Somebody may be trying to eavesdrop on you"

To avoid the warning, you may need to purchase a cert for mydomain.com or you may need to make your app available at secure.mydomain.com subdomain.

2007-03-31 11:11 PM

Sijin,

Not sure what you mean by "point secure....to mydomain".

Using my 'solution?' above, users browse to 'secure.mydomain.com' and get symlinked from the (cpanel created) public/secure subdir to the mydomain.com public dir.

So they are only 'pointing' from secure.mydomain.com to mydomain.com via symlink.

Will that not work w/ a cert purchased for 'secure.mydomain.com'?

Thanks again,

Jeff

2007-04-01 12:12 AM

I'm afraid that will not work. Symlinking will not help you avoid the warning message.

2007-04-01 12:41 AM

The way to get secure.mydomain.com to point to the same location in your file system as mydomain.com without a warning message popping up is to have a seperate vhost that listens on port 443 where the DocumentRoot is the same as mydomain.com's DocumentRoot

For example:

domain.com:
<VirtualHost IP_Address:80>
ServerAlias domain.com
DocumentRoot /home/username/public_html
....
secure.domain.com:
<VirtualHost IP_Address:443>
ServerAlias secure.domain.com
DocumentRoot /home/username/public_html
....
And yes, secure.domain.com would need to have its own DNS entry (A Record) in order for this to work.

I hope that helps, support should be able to do this for you no problem.

Cheers,

~William  

2007-04-01 01:26 AM

MN MLS - Buy/Sell Real Estate in Minnesota
hi. Where can i find the virtualHost files that cpanel generates?

(woah: apologies for the huge avatar)

2007-05-02 12:41 PM

sorry about that avatar issue.  RMagick is acting up.  I fixed it for you.  

The virtualHost entries are in the httpd.conf file which only the support staff have access to -- you can contact them if you need to know specific lines from it.  

Cheers,

~William

2007-05-02 12:50 PM

MN MLS - Buy/Sell Real Estate in Minnesota
ah i see, thanks for the clarification.

2007-05-02 03:26 PM

Hi,
how can I do following:
- wap.addon_domain1.com
- wap.addon_domain2.com
so that they point to different directories, not the same public.html/wap/ ?

2007-05-07 03:55 AM

Hi Xet,

The addon_domain1.com, addon_domain2.com are actually sub-domains of the main domain. So they will exist as sub-directories under public_html. As per your requirement the best possible way is to create 2 sub-directories wap and wap1 (2 different directories)using cpanel.

Thank you

2007-05-07 05:58 AM

I have a question regarding setting up a subdomain. I deploy my main rails application using capistrano. This symlinks the public_html file to the 'current' rails public folder. Setting up the subdomain symlink as described above (ln -s ~/subdomain_rails/public ~/public_html/subdomain) works until the next time the main application is re-deployed, but then the public_html symlink points to a different public folder.

One way to solve the problem would be to add a task to the capistrano recipe to create a new symlink:

desc "Set the proper symlink for the subdomain"
deploy.task :after_deploy do
 run "ln -s ~/subdomain_rails/public ~/public_html/subdomain"
end

This works but is a bit crude, is there a better way?

2007-07-10 05:44 AM

The only other way is to ask support to make the DocumentRoot of your main domain not public_html but public_html/something

that way - all your domains point to DocumentRoots that are folders within public_html and you don't have to add any further tasks to you cap deploy.  

2007-07-10 09:22 AM

MN MLS - Buy/Sell Real Estate in Minnesota
I'm confused.  When you say:

ServerName www.your-full-name-temp.com

Are you saying "this is a temporary replacement for the server name?"

Because when I registered my account, I took the tutorial at face value and registered it as tersesystems-temp.com :-/

Should this be just plain tersesystems.com?  And if so, how do i get it changed?

2007-10-24 06:20 PM

"ServerName www.your-full-name-temp.com" is for those users who don't have a registered domain name at the time of signing up. You can park your registered domain name over this temporary domain name to get it working .

2007-10-24 06:34 PM

So parking will change the server alias for Apache, but I still have to change the DNS entry with my registrar to make those changes publicly accessible?

2007-10-24 06:52 PM

Yes, parking will change the server alias for Apache. You will have to ask your domain registrar to point the nameservers of your registered domain to the ones that was mentioned in the welcome mail.

2007-10-24 07:01 PM

Excellent, and done.  Website says it should take between 24 and 36 hours.

2007-10-24 07:03 PM

Hi All,

Have a major issue with getting this setup correctly. Not having access to the httpd.conf + using c-panel is a major draw back in this instance. Ok enough rant :-

I have created my add-on domain (domain2.co.uk) - pointed my DNS records to my static IP address - followed the above instructions about creating the site folder under root and created the symlink

Now if I browse www.my-main-domain.com/domain2/ - I get the 2nd site -

Is there no way round this??
I should not be able to see the 2nd domain from the 1st

When I try to go www.domain2.co.uk - I get the welcome to Edwards page - Make sure you have an account........ (Maybe this is just DNS taking its time to propagate)

TIA


2007-10-30 11:05 AM

Gr8-Ideas Ltd - Managament by Innovation
you added domain2.co.uk as a addon domain for my-main-domain.com which means the document root is ~/public_html/domain2. In other words addon domains are the parked domains of sub-domains. So by using www.my-main-domain.com/domain2/ or www.domain2.my-main-domain.com or domain2.co.uk will yield the same result as all points to the same location.

2007-10-30 11:44 AM

HostingRails Support
Thanks Kumar for your reply. My real gripe here is not being able to add multiple root domains, all under 1 physical account & space.

I was hoping there was some magic way of hiding them from each other whilst still playing nice under the prison bars of C-Panel :-)

2007-10-30 02:35 PM

Gr8-Ideas Ltd - Managament by Innovation
After reading this post again, I see that the Author 'William' has given the solution to my dilemma 8 posts up starting - "The only other way is" - *** note to self; read dont skim topics before ranting

The solution is to get support to change www.my-main-domain.com document root to another folder under ~/public_html/ i.e. ~/public_html/my-main-domain/

Quote "that way - all your domains point to DocumentRoots that are folders within public_html"

add-on domains then become

~/public_html/domain2/
~/public_html/domain3/

This should mean that no domain is a sub directory of another and there is and no need for symlinks

Now if only C-panel only gave you the option to modify the main account doc root, as long as it was below your own public_html, this post would never have been needed.

Support ticket being opened now.

Many thanks William & co

2007-10-30 04:05 PM

Gr8-Ideas Ltd - Managament by Innovation
Greatideas- Yes that's possible - Support should be able to do this for you.

2007-10-30 04:36 PM

I have sym link ~/public_html/domain2 inside ~/railsapp/public
With an add on domain2 that points to it.

In my railsapp/public/.htaccess i have:
RewriteCond %{REQUEST_URI} ^/domain2.*
RewriteRule .* - [L]

when i browse to www.maindomain/domain2 i get index.htm
when i browse to www.domain2 i get a rails failed to start app error.
when i browse to www.domain2/index.htm it works.

Why is this? How do I get www.domain2 to work correctly?

Much thanks for the great post btw, being new to apache, this helps a lot.

2007-11-08 06:20 PM

If you could, please post a ticket with the support. Make sure that it contains all the details about the domains including the domain names and its corresponding document root.

Thank You,

2007-11-08 06:27 PM

HostingRails Support
after reading this thread I'm still not 100% sure wheather I understood everything correctly for my situation :-):

- I've got 2 Domains
- Both domains shall point to the exact same application on the server
- I want to use Google Apps as Email solution

Am I right that I could just set up my 2 Domains as Parked Domains over my "Sneak Peek" domain to make this setup work?

Thanks for any hint/help :-)

2008-05-06 06:20 PM

Well sneak-peak domain is actually a parked domain. It is parked over your account's "main domain name".

If you want both the domains to reflect to the same webpages (since you mentioned that both point to the same app)then, you will need to make either of the domain names as your Main domain name or Add-on domain name (depending on requirement).

And then park the other domain via Cpanel (incase it is a main domain).

If it is an Add-on domain then please post a ticket to support department to park the other domain name over this add-on domain..

I hope the above explanations makes sense..

2008-05-06 07:18 PM

Regards,
Rahul
How can I use an addon domain that has no .com suffix?

2008-05-07 12:50 PM

You can create/use domain names with suffix other than ".com" . What is the suffix name you want to use..?

2008-05-07 01:10 PM

Regards,
Rahul
I would like to use the suffix ".cl"

2008-05-07 02:44 PM

Hi Jawosis,

You have to register a domain with suffix ".cl" and create an addon-domain [with  suffix ".cl"] from your cpanel account.

2008-05-07 03:08 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up.