LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-03-2009, 06:50 AM   #1
Jacco
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Rep: Reputation: 0
unable to get virtual hosts to work


Hi hope someone can point me in the right direction cause im lost...
Here's the thing

I've got a Centos 5.3 box including php, mysql, webmin, apache2. This box is behind a router and has the internal ipadres 192.168.1.100. I have created some additional ipaddress in the same range (192.168.1.101 to 120)

I have 1 external ip address 11.123.123.123.

I have several domains registrated and pointing to my external ip address

My problem: I cant get the apache virtualhosts to work. I googled my ass of and tried just about everything... but nothing...
All the website that point to my external address see the first default server. So routing etc works.... But when i create a additional virtual server that will service www.site2.com it doesn't work . I've tried making a virtual host manually in httpd.conf and doing it automatically via webmin.... im lost...

www.site1.com should go to 192.168.1.100
www.site2.com should go to 192.168.1.101
etc. all ofcourse with different document roots.

Can someone pleasssssssssssssssssssssssssssssssssssssssse help me out...
 
Old 09-03-2009, 07:20 AM   #2
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
I'm not a network man but how do you expect your router to know that ip address 11.123.123.123 must be translated to 192.168.1.100 or 192.168.1.101 or 192.168.1.102 depending on the site? I assume that your router will simply take the first address. But as said, I'm not a network man.

The solution is to use namebased virtual hosting and all internal sites are on the same internal IP address (e.g. 192.168.1.100).

From my SLackware box
Code:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

# catch-all
<VirtualHost *:80>
    ServerAdmin me@mydomain
    DocumentRoot /srv/httpd/htdocs
    ServerName btd-techweb02
</VirtualHost>

# site 1
<VirtualHost *:80>
    ServerAdmin me@mydomain
    DocumentRoot /home/wim/www/site1/web
    ServerName site1.btd-techweb02
    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
    <Directory "/home/wim/www/site1/web">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

# site2
<VirtualHost *:80>
    ServerAdmin me@mydomain
    DocumentRoot /home/wim/www/site2/web
    ServerName site2.btd-techweb02
    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
    <Directory "/home/wim/www/site2/web">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Last edited by Wim Sturkenboom; 09-03-2009 at 07:21 AM.
 
Old 09-03-2009, 07:20 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,332
Blog Entries: 55

Rep: Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533
What Wim said ;-p
 
Old 09-03-2009, 07:25 AM   #4
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
Quote:
Originally Posted by unSpawn View Post
What Wim said ;-p
So THATs how you got 16,298 posts!

;-p
 
Old 09-03-2009, 07:38 AM   #5
Jacco
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Hi Wim,

I understand dat the router wil not know the difference.
I'll try your suggestion, but it looks very similar to other tutorials. (so it must be right..)

let you know in a sec

Quote:
Originally Posted by Wim Sturkenboom View Post
I'm not a network man but how do you expect your router to know that ip address 11.123.123.123 must be translated to 192.168.1.100 or 192.168.1.101 or 192.168.1.102 depending on the site? I assume that your router will simply take the first address. But as said, I'm not a network man.

The solution is to use namebased virtual hosting and all internal sites are on the same internal IP address (e.g. 192.168.1.100).

From my SLackware box
Code:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

# catch-all
<VirtualHost *:80>
    ServerAdmin me@mydomain
    DocumentRoot /srv/httpd/htdocs
    ServerName btd-techweb02
</VirtualHost>

# site 1
<VirtualHost *:80>
    ServerAdmin me@mydomain
    DocumentRoot /home/wim/www/site1/web
    ServerName site1.btd-techweb02
    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
    <Directory "/home/wim/www/site1/web">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

# site2
<VirtualHost *:80>
    ServerAdmin me@mydomain
    DocumentRoot /home/wim/www/site2/web
    ServerName site2.btd-techweb02
    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
    <Directory "/home/wim/www/site2/web">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
 
Old 09-03-2009, 07:52 AM   #6
Jacco
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
I've done the modifications... some how both websites end up at the directory of the first.... below the httpd.conf file regarding virtual server

Are there any changes to be made in the host file in /etc


# site 1
<VirtualHost *:80>
ServerAdmin admin@site1.nl
DocumentRoot /var/www/html/site1.nl
ServerName site1.nl
ErrorLog /var/log/httpd/error_log
CustomLog /var/log/httpd/access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
<Directory "/var/www/html/site1.nl">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

# site2
<VirtualHost *:80>
ServerAdmin admin@site2.nl
DocumentRoot /var/www/html/site2.nl
ServerName site2.nl
ErrorLog /var/log/httpd/error_log
CustomLog /var/log/httpd/access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
<Directory "/var/www/html/site2.nl">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
 
Old 09-03-2009, 08:03 AM   #7
Jacco
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Talking

It works!!!! Wim you're the man... I forgot on little thing... had the serverName site1.nl
i tried connecting to it via www.site1.nl
added a ServerAlias www.site1.nl and voila............. done... \

thank you thank you thank you
 
Old 09-03-2009, 11:54 AM   #8
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
graag gedaan

PS I've never used server aliases for my virtual hosts

Last edited by Wim Sturkenboom; 09-03-2009 at 11:56 AM.
 
  


Reply

Tags
vhosts


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
vsftpd, web uploads, vsftpd virtual users, apache virtual hosts, home directories jerryasher Linux - Software 7 02-18-2007 07:29 AM
virtual hosts, virtual ip's? kuplo Linux - Newbie 3 11-29-2005 09:44 PM
Unable to access local virtual hosts zeroGsa Linux - Networking 3 12-22-2004 02:39 PM
Unable to create virtual hosts in Apache figure8car Mandriva 2 12-05-2004 10:34 AM
Virtual Hosts Help please... vbp6us Linux - General 15 07-11-2003 05:08 AM


All times are GMT -5. The time now is 05:37 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration