LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 06-20-2009, 12:44 PM   #1
miragej
LQ Newbie
 
Registered: Nov 2008
Location: South Wales, UK
Distribution: Debian 6, Ubuntu 10.04
Posts: 25

Rep: Reputation: 0
Apache2 Local Subdomains


Hey guys, I have been searching for hours to try and find a way to get this to work, but I've had no success.

When I get stuck with something, I never go straight to a forum and ask for help, I actually enjoy trying to figure things out for myself, but this one really has me stumped.

I'm running a Debian Etch server, with Apache2 installed as a webserver. All I want is the ability to have subdomains.

EG, http://servername directs to /var/www/ and then http://php.servername directs to /var/www/phpmyadmin/

Im running Apache2, so my virtual host file is located at /etc/apache2/sites-available/default.



If I go to http://servername it's correct, and shows the contents of /var/www/ but if I go to http://php.servername it just times out.

The probablem has nothing to do with phpmyadmin, because I have tried other directories and it still times out.

Below is the important part of it.

Can anybody see why this does not work?


Code:
NameVirtualHost *:80

<VirtualHost *:80>

    DocumentRoot /var/www/
    ServerName localhost

</VirtualHost>



<VirtualHost *:80>

    DocumentRoot /var/www/phpmyadmin/
    ServerName php.localhost

</VirtualHost>

Thanks in advance,
Josh.
 
Old 06-20-2009, 03:07 PM   #2
60s TV Batman
Member
 
Registered: Oct 2004
Location: London (UK)
Distribution: Ubuntu 12.04
Posts: 60

Rep: Reputation: 17
I'm no expert, but will speculate that php.localhost has no specific meaning without some kind of DNS entry.

When I set up a subdomain on one of my servers (albeit for the Internet rather than localhost), I have to add a corresponding A record for that domain in its DNS record.

I'm guessing you have to do something similar locally to tell the system what to do with php.localhost. Perhaps you can use /etc/hosts to do this (a guess on my part).
 
Old 06-20-2009, 03:18 PM   #3
miragej
LQ Newbie
 
Registered: Nov 2008
Location: South Wales, UK
Distribution: Debian 6, Ubuntu 10.04
Posts: 25

Original Poster
Rep: Reputation: 0
Thanks for the reply, I shall have a look into that now.

Anybody else have any ideas?



Thanks again,

Josh.
 
Old 06-20-2009, 03:52 PM   #4
cmdln
Member
 
Registered: Apr 2009
Location: Lawrence, KS
Distribution: Debian, Centos
Posts: 102
Blog Entries: 1

Rep: Reputation: 24
Quote:
Originally Posted by miragej View Post
Thanks for the reply, I shall have a look into that now.

Anybody else
Sounds like you need an entry omin your /etc/hosts or full fleged DNS. What happens of you try to ping the server by this new name?
 
Old 06-20-2009, 03:59 PM   #5
miragej
LQ Newbie
 
Registered: Nov 2008
Location: South Wales, UK
Distribution: Debian 6, Ubuntu 10.04
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by cmdln View Post
Sounds like you need an entry omin your /etc/hosts or full fleged DNS. What happens of you try to ping the server by this new name?
Thanks for the reply.

So you think that I'm going to have to set up a DNS server just to have subdomains? :/

And when I ping http://servername I get a response, but when I ping http://php.severname I do not.


I dont know if this is correct, but in my /etc/hosts file I added the line:


Code:
192.168.0.10 servername php.servername


where 192.168.0.10 is the servers internal ip.

Thanks for your help,

Josh.
 
Old 06-20-2009, 08:16 PM   #6
fritz001
Member
 
Registered: Aug 2004
Posts: 119

Rep: Reputation: 18
NameVirtualHost 192.168.70.200:80

<VirtualHost redirect.domain.com:80>

ServerName redirect.domain.com
ServerAdmin postmaster@domain.com
DocumentRoot "/var/www/vhosts/losers100"

ErrorLog "/var/log/httpd/redirect.domain-error_log"
CustomLog "/var/log/httpd/redirect.domain-access_log" common

<Directory />
Options -Indexes FollowSymLinks
DirectoryIndex index.html
AllowOverride None
</Directory>

<Directory /var/www/vhosts/losers100>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

</VirtualHost>


<VirtualHost a-new-sobdamain.domain.com:80>
ServerName a-new-sobdamain.domain.com
ServerAdmin postmaster@domain.com
DocumentRoot "/var/www/vhosts/losers200"

ErrorLog "/var/log/httpd/a-new-sobdamain.domain-error_log"
CustomLog "/var/log/httpd/a-new-sobdamain.domain-access_log" common

<Directory />
Options -Indexes FollowSymLinks
AllowOverride None
</Directory>

<Directory /var/www/vhosts/losers200>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

<IfModule alias_module>

Include /etc/httpd/aliases

</IfModule>

</VirtualHost>


and you have to edit zone file for BIND to allow subdomains

ns IN A IP
www IN A IP
webmail IN A IP
mail IN A IP
a-new-sobdamain IN A IP

Last edited by fritz001; 06-20-2009 at 08:19 PM.
 
Old 06-20-2009, 10:31 PM   #7
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by miragej View Post
I dont know if this is correct, but in my /etc/hosts file I added the line:
Code:
192.168.0.10 servername php.servername
And did that work?

Below my /etc/hosts on the client
Code:
192.168.2.233   webserver01.athome      webserver01
192.168.2.233   rhc.athome              rhc
192.168.2.233   assets.athome           assets
192.168.2.233   44galena.athome         44galena
 
Old 06-21-2009, 10:57 AM   #8
miragej
LQ Newbie
 
Registered: Nov 2008
Location: South Wales, UK
Distribution: Debian 6, Ubuntu 10.04
Posts: 25

Original Poster
Rep: Reputation: 0
Thanks for your help guys.

I managed to get a subdomain working by adding a few entries to my clients host file. However, the subdomain is not redirecting properly.

A snippet of my virtual host file:


Code:
NameVirtualHost *

<VirtualHost *>

        DocumentRoot /var/www/live/
        ServerName localhost

</VirtualHost>


<VirtualHost *>

DocumentRoot /var/www/home/
ServerName home.localhost

</VirtualHost>

So now http://servername and http://home.servername are both accessable, but http://home.servername directs to /var/www/live even though is should direct to /var/www/home/

Does anybody know why this is happening?


Thanks again,
Josh.
 
Old 06-22-2009, 02:02 PM   #9
luisduenas
LQ Newbie
 
Registered: Dec 2008
Distribution: Debian - pero ya no.
Posts: 21

Rep: Reputation: 0
This is how I do the configuration.
the diference is that you use * for any ip address.

<VirtualHost ipaddress1.1.1.1>
DocumentRoot /home/where/www
ServerName www.domain.com
</VirtualHost>


Some test i did when it fails , change the default domain home's directory, and see if it all the domains change to this , maybe you need to check you dns info.

Also you can try using the logs for each site , and see if the acces is for the right site .

LogLevel emerg
CustomLog /home/log/acces.log "combined"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot access `/usr/local/apache2/modules/libphp5.so' gravesb Linux - Software 13 12-02-2011 02:56 AM
apache2 setup/test subdomains on LAN DeltaXFX Linux - Server 5 11-04-2007 10:16 AM
Subdomains on Apache2 with virtual hosts - how? <Ol>Origy Linux - Networking 2 08-18-2005 05:53 AM
apache2 local network problem HermanTheSheep Linux - Networking 4 12-07-2004 07:23 AM
Apache2 Server - not working outside local ip address range Robstro Linux - Networking 3 06-14-2004 05:32 PM


All times are GMT -5. The time now is 12:01 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration