LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 07-19-2011, 07:42 PM   #1
pov
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Rep: Reputation: Disabled
Apache 2.2 Virtual Hosts - Defaulting to main


First of all I've looked at "similar threads" without finding an answer. I'm setting up Name-based VH using an IP as the base.
The OS is CentOS 5.4

My config looks like:

NameVirtualHost 12.345.678.90:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#


<Directory "/home/dev1">
Order Deny,Allow
Allow from all
</Directory>


<VirtualHost 12.345.678.90:80>

DocumentRoot /var/www/html
ServerName localhost
</VirtualHost>

<VirtualHost 12.345.678.90:80>

DocumentRoot /home/dev1
ServerName dev1
</VirtualHost>

The names are of course not in DNS so to access the server from my local Windows machine I had to use the hosts file:

12.345.678.90 dev1

Entering dev1 in my browser *does* take me to the server but it takes me to default VH (DocumentRoot /var/www/html). What am I overlooking?

Thanks
 
Old 07-19-2011, 07:50 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I think you need the UserDir directive enabled http://httpd.apache.org/docs/2.2/mod/mod_userdir.html
 
Old 07-19-2011, 07:58 PM   #3
jhcaiced
Member
 
Registered: Mar 2009
Distribution: CentOS - Ubuntu - Debian
Posts: 83

Rep: Reputation: 27
I think you also have to configure the "fake" DNS for dev1 and localhost on your linux server otherwise the VirtualHost directive will not work.
 
Old 07-19-2011, 08:30 PM   #4
pov
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01 View Post
I think you need the UserDir directive enabled http://httpd.apache.org/docs/2.2/mod/mod_userdir.html
Thanks but that's not it. UserDir is directory mapping ala Alias and AliasMatch. None of them alter the DocumentRoot.

Last edited by pov; 07-19-2011 at 08:43 PM.
 
Old 07-19-2011, 08:32 PM   #5
pov
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jhcaiced View Post
I think you also have to configure the "fake" DNS for dev1 and localhost on your linux server otherwise the VirtualHost directive will not work.
Hmmmmm . . .okay I'll give that a go.
 
Old 07-20-2011, 10:28 AM   #6
pov
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jhcaiced View Post
I think you also have to configure the "fake" DNS for dev1 and localhost on your linux server otherwise the VirtualHost directive will not work.
I tried that - setting an entry in etc/hosts but it still didn't work.
 
Old 07-20-2011, 12:54 PM   #7
jhcaiced
Member
 
Registered: Mar 2009
Distribution: CentOS - Ubuntu - Debian
Posts: 83

Rep: Reputation: 27
Just did a small test, here are my results:
- Adding the hostname to /etc/hosts works fine, no need to restart anything...
- For testing if the hostname is working, on the Linux Server use 'ping myname',
do not use 'host myname' it didn't work.
- Remember to clear the cache of your browser after making changes to the configuration files.
 
Old 07-21-2011, 12:49 AM   #8
sandeep.sp
LQ Newbie
 
Registered: Jul 2011
Posts: 13

Rep: Reputation: Disabled
Don't include this virtual conf in the main apache conf file, instead make two files in /etc/httpd/conf.d/ as

1. default.conf
2. <your ip>.conf

And put the virtual host information there.

In default.conf Put /var/www/html as documentroot with default configuration.
Modify <your ip>.conf accordingly.



Regards,
Sandeep S
 
Old 07-21-2011, 01:15 AM   #9
leenucks
LQ Newbie
 
Registered: Jul 2011
Posts: 7

Rep: Reputation: Disabled
POV, here's another, easier, option, change all your 12.345.678.90:80 entries to *:80.

1. leave your hosts file as is since it directs your machine to resolve dev1 to your localhost
2. using name based VHs *:80 tells your apache process to listen and read host headers on port 80
3. when your browser hits your apache server it will take dev1 which is presented as a 'host header' to apache and look for the matching ServerName in your VH section and it will server up that content in it.

this is an excellent example: http://httpd.apache.org/docs/2.1/vho....html#purename
 
Old 07-21-2011, 01:16 AM   #10
leenucks
LQ Newbie
 
Registered: Jul 2011
Posts: 7

Rep: Reputation: Disabled
BTW,

<Directory "/home/dev1">
Order Deny,Allow
Allow from all
</Directory>

is just getting in the way

and make ServerName the first line in your VH stanza. it makes it easier to read..
 
Old 07-22-2011, 07:19 AM   #11
pov
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks to jhcaiced, sandeep.sp and leenucks for their answers. I tried leenucks' approach first because I mean c'mon . . way too simple. I started out using the wildcard instead of the IP so no way it will work. Except . . it did. lol. So thanks again. Oh but I'll keep my doc root first . . . . I like it that way.

-----------------------------
Not quite. It brings up the authentication which means it's finding the right directory but on login it attempts to find dev1/dev1 and of course gives a 404 error.

Last edited by pov; 07-22-2011 at 07:41 AM.
 
Old 07-22-2011, 01:16 PM   #12
leenucks
LQ Newbie
 
Registered: Jul 2011
Posts: 7

Rep: Reputation: Disabled
Quote:
Originally Posted by pov View Post
Thanks to jhcaiced, sandeep.sp and leenucks for their answers. I tried leenucks' approach first because I mean c'mon . . way too simple. I started out using the wildcard instead of the IP so no way it will work. Except . . it did. lol. So thanks again. Oh but I'll keep my doc root first . . . . I like it that way.

-----------------------------
Not quite. It brings up the authentication which means it's finding the right directory but on login it attempts to find dev1/dev1 and of course gives a 404 error.
if you're trying to make this harder for yourself, have at it.. :-). wildcards work very well... there are a few instances were you don't want wildcard but generally it makes migrations and setting up new non-ssl sites much easier.. best of luck..
 
Old 07-24-2011, 11:19 AM   #13
pov
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by leenucks View Post
if you're trying to make this harder for yourself, have at it.. :-). wildcards work very well... there are a few instances were you don't want wildcard but generally it makes migrations and setting up new non-ssl sites much easier.. best of luck..
Lol. I think you missed the point of my post which is "it worked." I was describing my initial reaction to your suggestion. But yeah the wildcards are it. Thanks again.

The problem now is that it calls a non-existent directory
 
  


Reply



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
Apache Virtual Hosts ll_oz_ll Linux - Server 3 10-23-2009 02:57 AM
Apache 2 and virtual hosts Ephracis Linux - Software 2 06-16-2008 05:37 AM
Apache with virtual hosts linuxmandrake Linux - Security 1 09-14-2006 12:53 PM
Apache 2 defaulting to first virtual host QtCoder Linux - Networking 7 02-16-2005 07:43 PM
Apache Virtual Hosts gbg Linux - Software 4 10-02-2003 08:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:54 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
Open Source Consulting | Domain Registration