Help - Search - Members - Calendar
Full Version: Unlimited subdomains using mod_vhost_alias
The Planet Forums > Control Panels > Plesk
HostCrest
(Updated Dec. 18...)

The following steps will allow you to offer "unlimited subdomains" for your clients on a Plesk system. Once you've completed these steps, the client can create a new subdomain by creating a new folder in the httpdocs or httpsdocs folder -- in other words, /usr/local/psa/home/vhosts/domain.com/httpdocs/newsub will be available via http://newsub.domain.com/. The usual http://www.domain.com/ , http://www.domain.com/webstat/ and (if applicable) https://www.domain.com/ URLs will continue to work, as well.

So here are the steps:

1. Add the VirtualDocumentRoot directive from mod_vhost_alias to your httpd.conf file; this setting will apply to all domains on your server.

Edit /usr/local/psa/apache/conf/httpd.conf and at the end of the file, add this line:
CODE
VirtualDocumentRoot /usr/local/psa/home/vhosts/%2+/httpdocs/%1

2. Add a wildcard subdomain record in the default DNS settings; this record will be added to each new domain you add (existing domains will need to have this added manually).

Log in to PSA as the Administrator, and click the Server button at the top. Then, click the DNS button to show the default DNS settings. Add a new A record here with
CODE
domain name: [b]*[/b].<domain>.

IP address: [b]<ip>[/b]
(Bold portions are to be added; unbolded text is already displayed on the form when added the record.)

3. Create a symbolic link for the www "subdomain", since the VirtualDocumentRoot directive will translate www.domain.com to ~domain/httpdocs/www. We'll make the change in the .skel directory, so it will apply to all new physical hosting accounts that will be added (existing clients will have to manually add the link and then change the owner of the link to the appropriate user to match the owner of the httpdocs directory).

Log in to your server and change user to root. Then execute the following commands:
CODE
cd /usr/local/psa/home/vhosts/.skel/httpdocs

ln -s . www

cd ../httpsdocs

ln -s . www


That's it!

This has some drawbacks (like the inability to control the number of subdomains allowed), but it's an easy way to offer subdomains to your clients on the Plesk server without using up additional domains in the 200-domain Plesk license.

Are there any serious side effects that I'm missing?? icon_smile.gif
KyleKL
is the httpd.conf file re-created every time you add or modify a domain? or is that the httpd.include?

That sounds like a great solution to the domain limitations.
HostCrest
QUOTE
Originally posted by Kyle
is the httpd.conf file re-created every time you add or modify a domain?  or is that the httpd.include?
httpd.include is updated, but httpd.conf seems to be untouched by the addition of domains, etc.
KyleKL
Wouldn't www. point to httpdocs/www ?

I can't seem to get this to work. Any ideas?
Postal
Hi I tried to get it to work but when I add the line to conf all my main domain links become broken.I can not log into any.Is there any section that this should be written to?
HostCrest
QUOTE
Originally posted by Kyle
Wouldn't www. point to  httpdocs/www ?

I can't seem to get this to work.   Any ideas?
You can create a symlink from httpdocs to www. Postal: This should solve your problem also... (Edit: stuff about FollowSymLinks removed because it doesn't apply.)

Anyway, I've done a bit more testing and everything seems fine. One other drawback to this approach is in the logging -- when http://www.domain.com/folder/ is accessed, the log reports a hit on /folder/...and when http://sub.domain.com/folder/ is accessed, the log also reports a hit on /folder/, and the subdomain information is lost. To me, this is not a big deal, and it's likely not a big issue for most other users. But if someone wants to try to tackle this issue, feel free. icon_smile.gif

I've updated my original message in this thread with the changes to support www.
KyleKL
CODE
Forbidden

You don't have permission to access / on this server.


This is the error message I get, any ideas?
HostCrest
QUOTE
Originally posted by Kyle
CODE
Forbidden

You don't have permission to access / on this server.


This is the error message I get, any ideas?
Kyle, there is an "Options SymLinksIfOwnerMatch" directive in the httpd.conf file. So if you create the symlink manually, you have to chown it to the appropriate user. When the symlink is automatically created, on the other hand, the owner is correctly set.
Postal
non www links are broken

Hi I tried to get it to work but when I add the line to conf all my main domain links become broken.I can not log into any.Is there any section that this should be written to? Fixed


Now only my www.domain.name works I can't access my site using domain.name.I must have a www in front
HostCrest
Hmm... What happens on my system is that http://domain.com/file.html is automatically forwarded to http://www.domain.com/file.html and it's displayed properly.

What kind of error do you get when accessing the domain without www? Also look in error_log to see if it has more details...
Postal
Not Found
The requested URL was not found on this server
HostCrest
QUOTE
Originally posted by Postal
Not Found
The requested URL was not found on this server
If you look at error_log, it will show you exactly which file it was looking for...that'll give you a hint about why it failed.
Postal
[Wed Dec 19 16:46:46 2001] [error] [client 64.231.64.17]
File does not exist:
/usr/local/psa/home/vhosts/com/httpdocs/hostebiz/
Postal
I should let you know that the subdomains are working great.
Postal
The first is an error with a working www.domain.com.
The second is the error with the non working domain.com
The path changes when I put it the virtual root in the http.conf

Any Suggestions

==============================================

[client 64.231.64.17]
File does not exist:
/usr/local/psa/home/vhosts/hostebiz.com/httpdocs/www/index2.htm

==============================================

[Wed Dec 19 17:32:52 2001] [error] [client 64.231.64.17] File does not exist: /usr/local/psa/home/vhosts/com/httpdocs/hostebiz/
Ales
Well, I have some problems too. I beleive this might be related to other errors above...

I have done the above procedure and it mostly works great. BTW, I decided to manually add subdomains in the future rather than adding *. wildchard, so I do have a way of limiting subdomains per customer.

One notice: you MUST have 'www' as A-record and not CNAME or it won't work...! Plesk puts www in the DNS as a CNAME, if you let it do it by default. Khm... I needed half an hour to figure this out... rolleyes.gif

But, I also stumbled on a bigger problem: I have a couple of frame redirects. These domains also have httpdocs directory so I added the www symlink and chowned it. They don't have usual owners but rather root/psaadm. Now, when I try to reach domain.com it doesn't work! It works only with www.domain.com icon_sad.gif

Any ideas...?

Ales
HostCrest
Ack! There's a problem in applying VirtualDocumentRoot /usr/local/psa/home/vhosts/%2+/httpdocs/%1 server-wide because it doesn't address the httpsdocs folder!

The easy workaround is to map httpsdocs to httpdocs -- http://www.domain.com/ and https://www.domain.com/ would then share content, and there wouldn't be any difference between httpdocs and httpsdocs as there is now. But that wouldn't be desirable to everyone...

The more difficult (but more flexible) workaround is to remove the VirtualDocumentRoot directive from httpd.conf and place it in vhost.conf and vhost_ssl.conf for each domain. So, vhost.conf would have:
CODE
ServerAlias  *.domain.com

VirtualDocumentRoot /usr/local/psa/home/vhosts/%2+/httpdocs/%1
and vhost_ssl.conf would have:
CODE
ServerAlias  *.domain.com

VirtualDocumentRoot /usr/local/psa/home/vhosts/%2+/httpsdocs/%1
But the "domain.com" part is dependent on the client's actual domain, and I don't think there's a way to automatically write vhost.conf with that filled in correctly. Is there? Or maybe a more generic form of ServerAlias that would still work?

As a last resort, it's not a monumental task for the server administrator to manually add these vhost.conf and vhost_ssl.conf files for domains where appropriate. A script could even be written to make it a little easier (but still manual).
HostCrest
QUOTE
Originally posted by Ales
But, I also stumbled on a bigger problem: I have a couple of frame redirects. These domains also have httpdocs directory so I added the www symlink and chowned it. They don't have usual owners but rather root/psaadm. Now, when I try to reach domain.com it doesn't work! It works only with www.domain.com icon_sad.gif
Ales, try using the vhost.conf and vhost_ssl.conf solution in my last message... Since you're already managing the process manually (for subdomain addition), creating those two files shouldn't be that much of a hassle for you. For the frame forwarded domains, you could just leave out the vhost.conf file and it would work properly.
Postal
The first is an error with a working www.domain.com.
The second is the error with the non working domain.com
The path changes when I put it the virtual root in the http.conf

Any Suggestions

==============================================

[client 64.231.64.17]
File does not exist:
/usr/local/psa/home/vhosts/hostebiz.com/httpdocs/www/index2.htm

==============================================

[Wed Dec 19 17:32:52 2001] [error] [client 64.231.64.17] File does not exist: /usr/local/psa/home/vhosts/com/httpdocs/hostebiz/
HostCrest
QUOTE
Originally posted by Postal [client 64.231.64.17]  
File does not exist:  
/usr/local/psa/home/vhosts/hostebiz.com/httpdocs/www/index2.htm
Does that file exist? Do you have the same owner for that file, the 'www' symlink, and the httpdocs folder?
QUOTE
Originally posted by Postal [Wed Dec 19 17:32:52 2001] [error] [client 64.231.64.17] File does not exist: /usr/local/psa/home/vhosts/com/httpdocs/hostebiz/ [/B]
I don't know why mine works and yours does not. I must admit that the mapping above (/vhosts/com/httpdocs/hostebiz) makes sense for "VirtualDocumentRoot /usr/local/psa/home/vhosts/%2+/httpdocs/%1"... But it has not been a problem on my system. If you use vhost.conf files in the /conf folders of your domains, you should be able to avoid this problem.
rhordern
Hi, I tried to add unlimited domains to just one site so I added :
ServerAlias *.domain.com
VirtualDocumentRoot /usr/local/psa/home/vhosts/%2+/httpdocs/%1
to the vhost.conf file fin the conf directory of the domain I wanted it for
I then created the www symlink and went into plesk removed the cname for www.domain.com
and created an a record in its place
Then I created an A record called test.domain.com but when I go to test.domain.com I get the default page saying that the domain is not configured ...

Could someone please help me ... What I'm looking for is to manually add subdomains to any site that I want to, I don't want unlimited subs and not for all sites ...

Richard
Ales
Hmm... I would atleast expect an error page... It looks to me like apache is not taking your directive into account. Did you try completely restarting it?

BTW, did you chown the www symlink? And does subdirectory test exist?

Ales
rhordern
I actually rebooted the server !!!!
I have created a directory called test but am I supposed to chown it to root permissions?
ANd the symlink is it ment to be the users permissions?? I don't think that it would stop test.domain.com from working but i'll give it a go,

Richard
rhordern
The symlink now works as When I open www.domain.com/www/
it opens www.domain.com
is it possible that it doesn't work because there is an alias match in the same file??? (So that I can access www.domain.com/domain/domain2.com )

Richard
Ales
I remember you said you'd reset icon_smile.gif

www symlink should be:

user: ftp user name, whatever it is
group: psacln

Subdir test should be the same. I believe both the directives should work together...

Ales
rhordern
thats what I have done but it doesn't work !!
I'll post you what I've got in the vhost.conf dir

richard
rhordern
Here is what I've got in the vhost.conf file :
AliasMatch ^/domain/([^/]+)(/(.*))? /usr/local/psa/home/vhosts/$1/httpdocs/$3
ServerAlias *.domain.com
VirtualDocumentRoot /usr/local/psa/home/vhosts/%2+/httpdocs/%1

Just a thought, this domain is a name based site it doesn't have to be an IP based one does it?

Richard
rhordern
Found problem, I am stupid !!! I forgot to replace domain.com by my actual domain name, now works like a bird !!!!
Ales
icon_biggrin.gif
joseph
php script can't be display properly!
joseph
webmail.domain.com gone?
rhordern
No not unless you removed the A record,

Richard
joseph
How about php script not displaying properly..
have you tested yet?
rhordern
No but I will soon. Have you tried just running a script from a normal directory on a different site... On of my customers says that he can only get his asp scripts to work from the httpdocs root and not in a directory...

I think that it needs looking into, also I want to find out if there is a way to make CGI scripts work everywhere like on the raqs...

Richard
nat
QUOTE
link is broken  
The first is an error with a working www.domain.com.  
The second is the error with the non working domain.com  
The path changes when I put it the virtual root in the http.conf  

File does not exist:
/usr/local/psa/home/vhosts/hostebiz.com/httpdocs/www/index2.htm  

File does not exist:
/usr/local/psa/home/vhosts/com/httpdocs/hostebiz/


I had same problem.

To fix this make sure you have the www checked in plesk. icon_biggrin.gif

-----------------

If anyone has trouble with the subdomains only showing the default page of the main domain, add this directive to the domain's vhost.conf file:
UseCanonicalName Off

-----------------

I tested perl, asp, and php in these domain's main domain, subdomain, and in a web_user directory. All worked ok for me.

More information on mod_vhost_alias can be found at:
http://httpd.apache.org/docs/mod/mod_vhost_alias.html
joseph
Show me a subdomain of your site with the folder created. I like to see the php in demo.
rhordern
HI, I've put a phpinfo file at http://test.philipsantiques.com

So that you can see that php works ...
Is that enough or is there some specefic function that you would like me to try?

Richard
nat
The way the VirtualDocumentRoot is defined, it kills FrontPage for that domain. icon_sad.gif

Is this just me or has anyone else ran into FrontPage problems using this method of providing unlimited subdomains.

/var/log/httpd/fpexec_log says this:

[2002-02-02 08:35:28]: cannot stat directory: (/home/httpd/vhosts/mydomain.com/httpdocs/www)

I guess frontpage won't follow the symlink when its looking for the extensions.


ps: The path above is correct. I have the rpm installation of plesk.
jo-jo
seems that the webmail dosent work anymore (the dns a record is still in place) anyone found a fix for this?
rhordern
Sorry, it still works for me ...

By an chench have you goy*t a directory called webmail ? if so this might be a cause of conflict ...

Richard
jo-jo
nope, sure dont...
Gyrbo
This is verry interesting.
But what happens if you access http://domain.com?
I will look for the subdomain "domain" of the domain "com" right?

It's a nice trick, but I don't think it's usefull in production state.
rhordern
i've just installed it on the whole server and not just on each private domain and I can't access webmail anymore either !
ANyone found an answer to this?
Also I have just updated to plesk 2.5 and CGI scripts don't work anymore !!!

any ideas ??
mystery
nat you are the MAN!!!!

that usecanonical name was just what i needed!!! OH YEAH!!!

icon_smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.