View previous topic :: View next topic |
Author |
Message |
jtp755 l33t


Joined: 01 Sep 2003 Posts: 691 Location: USA
|
Posted: Thu Feb 19, 2004 10:57 pm Post subject: [How-To] Setting up sub-domains with Apache2 |
|
|
How to Setup a Subdomain with Apache2
1) I am going to assume that you already have Apache2 installed and running properly. If not drop me an email and ill see if I can come up with a how-to on it.
2) Go to /etc/apache2/conf/vhosts and open the vhosts.conf file in your text editor
3) You will need to know all of the DocumentRoot directories of the sub-domains you want to create.
4) Start of by creating a NamedVirtualHost for *:80.
a) At the end of vhosts.conf add a line that says: NamedVirtualHost *:80 and hit enter to go to the next line.
5) Now we will start creating the VirtualHosts. First you will want to create one for www.yourdomain.com.
a) <VirtualHost *:80>
ServerName yourdomian.com
ServerAlias www.yourdomain.com
DocumentRoot /path/to/your/main/DocumentRoot
</VirtualHost>
6) Now we can setup the sub-domains like this:
a) <VirtualHost *:80>
ServerName sub1.yourdomain.com
DocumentRoot /path/to/DocumentRoot/of/sub1
</VirtualHost>
b) <VirtualHost *:80>
ServerName sub2.yourdomain.com
DocumentRoot /path/to/DocumentRoot/of/sub2
</VirtualHost>
c) <VirtualHost *:80>
ServerName sub3.yourdomain.com
DocumentRoot /path/to/DocumentRoot/of/sub2
</VirtualHost>
d) And so on and so on.
7)Now I will try my best to explain Redirects in a nutshell. Redirects are used to redirect something to another page, hence the name Redirect. There are four kinds of Redirects which are, temp, permanent, seeother, and gone. You can find out the descriptions Here. I will use only permanents for this how-to.
Example: Say one your sub-domains in your main DocumentRoot and you want to set it up so that if someone types in www.yourdomain.com/sub1 it will redirect to sub1.yourdomain.com. You would accomplish this by putting a Redirect permanent directive in your main VirtualHost. For this to work right I am pretty sure sub1 has to be in the main DocumentRoot specified above.
a) <VirtualHost *:80>
ServerName yourdomian.com
ServerAlias www.yourdomain.com
DocumentRoot /path/to/your/main/DocumentRoot
Redirect permanent /sub1 http://sub1.yourdomain.com
</VirtualHost>
b) <VirtualHost *:80>
ServerName yourdomian.com
ServerAlias www.yourdomain.com
DocumentRoot /path/to/your/main/DocumentRoot
Redirect permanent /sub1 http://sub1.yourdomain.com
Redirect permanent /sub2 http://sub2.yourdomain.com
</VirtualHost>
8.) Now you can save and close vhosts.conf
9) Next you will want to restart/reload Apache2.
a) /etc/init.d/apache2 restart
b) /etc/init.d/apache2 reload
10) Now go and test to see if your sub-domains work. If not check back here again or try Here.
---------------------------------------------------------
Thanks for using this guide and I hope that it helps you in some way. If you find any mistakes please email me [jtp755 at nc dot rr dot com] and let me know and I will fix it. _________________ www.EternalFireProof.com
Registered Linux User #334610 |
|
Back to top |
|
 |
beandog Bodhisattva


Joined: 04 May 2003 Posts: 2066 Location: /usa/utah
|
Posted: Thu Jul 15, 2004 5:10 pm Post subject: |
|
|
Um, I think its NameVirtualHost not NamedVirtualHost _________________ If it ain't broke, tweak it. dvds | blurays | blog | wiki |
|
Back to top |
|
 |
GentooBox Veteran


Joined: 22 Jun 2003 Posts: 1168 Location: Denmark
|
Posted: Thu Jul 15, 2004 6:42 pm Post subject: |
|
|
I made a bash script a long time ago.
the syntax was like this:
wonder -s latex mydomain.com
that would make a subdomain called latex in mydomain.com
but I cant find the script :S - if I find it, I post it here.
EDIT: Woooho... this is post number 999. _________________ Encrypt, lock up everything and duct tape the rest |
|
Back to top |
|
 |
neutcomp Tux's lil' helper

Joined: 12 Aug 2004 Posts: 112 Location: The Netherlands
|
Posted: Thu Oct 14, 2004 6:57 pm Post subject: not working :( |
|
|
Hello,
I followed your how-to everything whent fine. But its not working.
vhost.conf
Code: |
NameVirtualHost *:80
<VirtualHost *:80>
ServerName neutcomp.xs4all.nl
ServerAlias neutcomp.xs4all.nl
DocumentRoot /wwwroot
</VirtualHost>
<VirtualHost *:80>
ServerName gallery.neutcomp.xs4all.nl
DocumentRoot /wwwroot/gallery
</VirtualHost>
<VirtualHost *:80>
ServerName neutcomp.xs4all.nl
ServerAlias neutcomp.xs4all.nl
DocumentRoot /wwwroot
Redirect permanent /gallery http://gallery.neutcomp.xs4all.nl
</VirtualHost> |
I dont really know whats the difference:
Code: | ServerName neutcomp.xs4all.nl
ServerAlias neutcomp.xs4all.nl |
Hope someone can help me out?
Thanxx
Bjorn  |
|
Back to top |
|
 |
jtp755 l33t


Joined: 01 Sep 2003 Posts: 691 Location: USA
|
Posted: Thu Oct 14, 2004 10:29 pm Post subject: |
|
|
you are missing a d in NameVirtualHost *:80 it should read:
Code: | NamedVirtualHost *:80 |
let me know if it still doesnt work.
Also you dont need that 3rd declaration. just move the Redirect Permanent to the top declaration and it should be fine. _________________ www.EternalFireProof.com
Registered Linux User #334610 |
|
Back to top |
|
 |
neutcomp Tux's lil' helper

Joined: 12 Aug 2004 Posts: 112 Location: The Netherlands
|
Posted: Fri Oct 15, 2004 6:31 am Post subject: |
|
|
Oke still not working
vhosts.conf
Code: | NamedVirtualHost *:80
<VirtualHost *:80>
ServerName neutcomp.xs4all.nl
ServerAlias neutcomp.xs4all.nl
DocumentRoot /wwwroot
Redirect permanent /gallery http://gallery.neutcomp.xs4all.nl
</VirtualHost>
<VirtualHost *:80>
ServerName neutcomp.xs4all.nl
ServerAlias neutcomp.xs4all.nl
DocumentRoot /wwwroot
</VirtualHost>
<VirtualHost *:80>
ServerName gallery.neutcomp.xs4all.nl
DocumentRoot /wwwroot/gallery
</VirtualHost> |
thanxx for your help
Bjorn  |
|
Back to top |
|
 |
jtp755 l33t


Joined: 01 Sep 2003 Posts: 691 Location: USA
|
Posted: Sat Oct 16, 2004 7:01 pm Post subject: |
|
|
neutcomp wrote: | Oke still not working
vhosts.conf
Code: | NamedVirtualHost *:80
<VirtualHost *:80>
ServerName neutcomp.xs4all.nl
ServerAlias neutcomp.xs4all.nl
DocumentRoot /wwwroot
Redirect permanent /gallery http://gallery.neutcomp.xs4all.nl
</VirtualHost>
<VirtualHost *:80>
ServerName neutcomp.xs4all.nl
ServerAlias neutcomp.xs4all.nl
DocumentRoot /wwwroot
</VirtualHost>
<VirtualHost *:80>
ServerName gallery.neutcomp.xs4all.nl
DocumentRoot /wwwroot/gallery
</VirtualHost> |
thanxx for your help
Bjorn  |
Try
Code: | NamedVirtualHost *:80
<VirtualHost *:80>
ServerName neutcomp.xs4all.nl
ServerAlias neutcomp.xs4all.nl
DocumentRoot /wwwroot
Redirect permanent /gallery http://gallery.neutcomp.xs4all.nl
</VirtualHost>
<VirtualHost *:80>
ServerName gallery.neutcomp.xs4all.nl
DocumentRoot /wwwroot/gallery
</VirtualHost> |
and make sure that in /etc/apache2/conf/apache2.conf you have uncommented the line like below:
Code: |
###
### Virtual Hosts
###
# We include different templates for Virtual Hosting. Have a look in the
# vhosts directory and modify to suit your needs.
Include conf/vhosts/vhosts.conf
#Include conf/vhosts/dynamic-vhosts.conf
#Include conf/vhosts/virtual-homepages.conf
|
Is neutcomp a subdomain of xs4all.com? that may be the problem. _________________ www.EternalFireProof.com
Registered Linux User #334610 |
|
Back to top |
|
 |
neutcomp Tux's lil' helper

Joined: 12 Aug 2004 Posts: 112 Location: The Netherlands
|
Posted: Sat Oct 16, 2004 8:05 pm Post subject: |
|
|
Yes its a subdomein from xs4all.
xs4all is a internet provider. And if your nick would be "luckyou"
than luckyou.xs4all.nl directs to your ipadres.
When I remove the # for the line Include conf/vhosts/vhosts.conf
and restart I get this message in the error log:
Code: | Symbolic link not all
owed: /wwwroot
|
I think because /wwwroot is a ln -s
So I changed the symbolic link to /var/www/localhost/htdocs/
But stil not working.
Thanxx
Bjorn |
|
Back to top |
|
 |
jtp755 l33t


Joined: 01 Sep 2003 Posts: 691 Location: USA
|
Posted: Mon Oct 18, 2004 2:05 am Post subject: |
|
|
you can use the first symbolic link /wwwroot but you need to make sure that /wwwroot or whereever it points is owned by apache. i think thats why you get that message. _________________ www.EternalFireProof.com
Registered Linux User #334610 |
|
Back to top |
|
 |
Vyeperman Tux's lil' helper

Joined: 18 Dec 2003 Posts: 89
|
Posted: Mon Apr 11, 2005 6:29 am Post subject: |
|
|
any idea why djc.gentoowarp.com/anthony.gentoowarp.com doesn't work and vye.gentoowarp.com does?
Code: |
NameVirtualHost *:80
<VirtualHost *:80>
ServerName vye.gentoowarp.com
DocumentRoot /home/www/vye
</VirtualHost>
<VirtualHost *:80>
ServerName djc.gentoowarp.com
DocumentRoot /home/www/djc
</VirtualHost>
<VirtualHost>
ServerName anthony.gentoowarp.com
DocumentRoot /home/www/anthony
</VirtualHost>
<VirtualHost *:80>
ServerName gentoowarp.com
ServerAlias www.gentoowarp.com
DocumentRoot /home/www
Redirect permanent /vye http://vye.gentoowarp.com
Redirect permanent /djc http://djc.gentoowarp.com
Redirect permanent /anthony http://anthony.gentoowarp.com
</VirtualHost> |
djc, anthony, and vye are both symlinks in my root dir
They have same permissions...
Code: |
ls -n /home/www
lrwxrwxrwx 1 0 0 19 Apr 10 15:06 djc -> /home/ftpusers/djc/
lrwxrwxrwx 1 0 0 23 Apr 10 15:06 anthony -> /home/ftpusers/anthony/
lrwxrwxrwx 1 0 0 19 Apr 10 15:06 vye -> /home/ftpusers/vye/
|
Here too.....
Code: |
ls -n /home/ftpusers/
total 0
drwxr-xr-x 4 1010 410 120 Apr 10 15:04 anthony
drwxr-xr-x 3 81 81 72 Apr 9 22:45 djc
drwxr-xr-x 2 1010 410 48 Apr 10 15:01 vye
|
whats going on? Try those url's in your browser. for example gentoowarp.com/anthony or djc and it will change to anthony.gentoowarp.com but it wont' actually load the page you'll get an error. What causes this I don't understand. _________________ -Vyeperman |
|
Back to top |
|
 |
jtp755 l33t


Joined: 01 Sep 2003 Posts: 691 Location: USA
|
Posted: Mon Apr 11, 2005 10:53 am Post subject: |
|
|
make sure all of the vhost have *8:80 in them.
also try moving the
Code: |
<VirtualHost *:80>
ServerName gentoowarp.com
ServerAlias www.gentoowarp.com
DocumentRoot /home/www
Redirect permanent /vye http://vye.gentoowarp.com
Redirect permanent /djc http://djc.gentoowarp.com
Redirect permanent /anthony http://anthony.gentoowarp.com
</VirtualHost>
|
to being the first thing in vhost.conf.
then reload apache (/etc/init.d/apache2 reload)
and try. _________________ www.EternalFireProof.com
Registered Linux User #334610 |
|
Back to top |
|
 |
Vyeperman Tux's lil' helper

Joined: 18 Dec 2003 Posts: 89
|
Posted: Mon Apr 11, 2005 1:40 pm Post subject: |
|
|
Is this the way you said it should look?
Code: |
NameVirtualHost *8:80
<VirtualHost *8:80>
ServerName gentoowarp.com
ServerAlias www.gentoowarp.com
DocumentRoot /home/www
Redirect permanent /vye http://vye.gentoowarp.com
Redirect permanent /djc http://djc.gentoowarp.com
Redirect permanent /anthony http://anthony.gentoowarp.com
</VirtualHost>
<VirtualHost *8:80>
ServerName vye.gentoowarp.com
DocumentRoot /home/www/vye
</VirtualHost>
<VirtualHost *8:80>
ServerName djc.gentoowarp.com
DocumentRoot /home/www/djc
</VirtualHost>
<VirtualHost *8:80>
ServerName anthony.gentoowarp.com
DocumentRoot /home/www/anthony
</VirtualHost> |
And when restarting apache2 I get
Code: |
# /etc/init.d/apache2 restart
* Stopping apache2...
[Mon Apr 11 05:39:42 2005] [error] (EAI 2)Name or service not known: Cannot resolve host name *8 --- ignoring!
[Mon Apr 11 05:39:42 2005] [error] (EAI 2)Name or service not known: Cannot resolve host name *8 --- ignoring!
[Mon Apr 11 05:39:42 2005] [error] (EAI 2)Name or service not known: Cannot resolve host name *8 --- ignoring!
[Mon Apr 11 05:39:42 2005] [error] (EAI 2)Name or service not known: Cannot resolve host name *8 --- ignoring!
[Mon Apr 11 05:39:42 2005] [error] (EAI 2)Name or service not known: Cannot resolve host name *8 --- ignoring! [ ok ]
* Starting apache2... [ ok ] |
Maybe I understood you wrong... _________________ -Vyeperman |
|
Back to top |
|
 |
krystalogik n00b

Joined: 14 Apr 2003 Posts: 1
|
Posted: Mon Apr 11, 2005 6:35 pm Post subject: |
|
|
I'm pretty sure the *8:80 was a typo, that should be *:80 |
|
Back to top |
|
 |
Vyeperman Tux's lil' helper

Joined: 18 Dec 2003 Posts: 89
|
Posted: Mon Apr 11, 2005 7:21 pm Post subject: |
|
|
Then I'm still in the same position, because as you can see the url's ( http://gentoowarp.com/djc and http://gentoowarp.com/anthony ) do not work. But http://gentoowarp.com/vye does? Here is my vhosts again, I have no idea what is causing vye to work but not the others.
Code: | NameVirtualHost *:80
<VirtualHost *:80>
ServerName gentoowarp.com
ServerAlias www.gentoowarp.com
DocumentRoot /home/www
Redirect permanent /vye http://vye.gentoowarp.com
Redirect permanent /djc http://djc.gentoowarp.com
Redirect permanent /anthony http://anthony.gentoowarp.com
</VirtualHost>
<VirtualHost *:80>
ServerName vye.gentoowarp.com
DocumentRoot /home/www/vye
</VirtualHost>
<VirtualHost *:80>
ServerName djc.gentoowarp.com
DocumentRoot /home/www/djc
</VirtualHost>
<VirtualHost *:80>
ServerName anthony.gentoowarp.com
DocumentRoot /home/www/anthony
</VirtualHost>
|
I don't see anything in error_log yet and permissions are still the same.
--Thanks. _________________ -Vyeperman |
|
Back to top |
|
 |
jtp755 l33t


Joined: 01 Sep 2003 Posts: 691 Location: USA
|
Posted: Tue Apr 12, 2005 2:51 am Post subject: |
|
|
alright....compare the groups that each dir is owned by.....make sure they are all the same as in all are owned by apache2 and are part of the same group.
next look in /etc/apache2/conf/commonapache2.conf and see what is defined for vye and not for the rest...in mine i have something along the lines of:
Code: |
<Directory /dir/to/webroot>
Options Indexes MultiViews
AllowOverride All
<IfModule mod_access.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
|
now make sure if you want to show all the files in the dir (indexing) that there is no - in front of indexes.
if you dont want to show the files and want to show a webpage make sure it shows "-Indexes"
try adding that for each vhost you want. and reload apache2 then post back. _________________ www.EternalFireProof.com
Registered Linux User #334610 |
|
Back to top |
|
 |
|