LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-22-2007, 07:29 AM   #1
jmoschetti45
Member
 
Registered: Oct 2004
Location: Michigan
Distribution: Debian Squeeze (2.6.32-5)
Posts: 137
Blog Entries: 1

Rep: Reputation: 17
Apache Virtual Host Annoyance


For some reason, I have to set up two virtual hosts for each domain, since www.example.com and example.com don't work properly unless I setup both. Is there a way around this?
 
Old 03-22-2007, 08:48 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,159
Blog Entries: 1

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
You have to add
Code:
ServerAlias example.com *.example.com
inside your <VirtualHost>..</VirtuaHost>, assuming that www.example.com is your ServerName

Regards
 
Old 03-23-2007, 05:14 AM   #3
jmoschetti45
Member
 
Registered: Oct 2004
Location: Michigan
Distribution: Debian Squeeze (2.6.32-5)
Posts: 137

Original Poster
Blog Entries: 1

Rep: Reputation: 17
Thanks, that's fixed. On to the next problem...

The default server is set to serve from /var/www/html, and all the virtual hosts are under /home/vhosts. Now, when I enter the server's IP directly, or a domain name that's not configured, I end up at the jmoschetti45.com page, not the one I'm looking for in /var/www/html. Any ideas?


Here's what I have in httpd.conf:

Quote:
<VirtualHost jmoschetti45.com:80>
DocumentRoot /home/vhosts/mcomp
ServerName jmoschetti45.com
<Directory "/home/vhosts/mcomp">
allow from all
Options +Indexes
</Directory>
ServerAlias *.jmoschetti45.com
</VirtualHost>

<VirtualHost lynchsex.com:80>
DocumentRoot /home/vhosts/lynchsex
ServerName lynchsex.com
<Directory "/home/vhosts/lynchsex">
allow from all
Options +Indexes
</Directory>
ServerAlias *.lynchsex.com
</VirtualHost>

<VirtualHost radio276.com:80>
DocumentRoot /home/vhosts/radio276
ServerName radio276.com
<Directory "/var/www/html">
allow from all
Options +Indexes
</Directory>
ServerAlias www.radio276.com
</VirtualHost>

<VirtualHost jmoschetti45.de:80>
DocumentRoot /home/vhosts/mcomp
ServerName jmoschetti45.de
<Directory "/home/vhosts/mcomp">
allow from all
Options +Indexes
</Directory>
ServerAlias www.jmoschetti45.de
</VirtualHost>

<VirtualHost marquettedems.org:80>
DocumentRoot "/home/vhosts/marquettedems"
ServerName marquettedems.org
<Directory "/home/vhosts/marquettedems">
allow from all
Options +Indexes
</Directory>
ServerAlias *.marquettedems.org
</VirtualHost>
 
Old 03-23-2007, 05:49 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,159
Blog Entries: 1

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
Quote:
when I enter the server's IP directly, or a domain name that's not configured, I end up at the moschetti45.com page
This is the normal behavior. If you give the ip address or a domain that points to that ip but it's not configured in vhosts, then apache shows the default site, which is the one defined by ServerName in the main server configuration in httpd.conf.
Quote:
<VirtualHost jmoschetti45.com:80>
Note that there is no need to write the domain name inside the <VirtualHost> tag. Just use:
Code:
<VirtualHost *:80>
 
Old 03-23-2007, 11:33 AM   #5
jmoschetti45
Member
 
Registered: Oct 2004
Location: Michigan
Distribution: Debian Squeeze (2.6.32-5)
Posts: 137

Original Poster
Blog Entries: 1

Rep: Reputation: 17
The ServerName is set to radio276.com, so I don't see why it's going to jmoschetti45.com as the default page.
 
Old 03-24-2007, 09:54 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,159
Blog Entries: 1

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
It's going to jmoschetti45.com because it's the first vhost in the list of vhosts. You can put radio276.com first, to show this site when a client does a request by ip address.
 
  


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
apache virtual host help? paddyjoy Linux - Server 4 09-19-2006 05:49 AM
Apache - Name virtual host tisource Linux - Networking 5 03-03-2006 02:52 AM
apache and virtual host diverge Linux - Networking 2 01-11-2004 02:45 AM
Virtual host and apache Samspeed Linux - General 8 08-06-2003 07:41 AM
apache virtual host mimi Linux - General 1 04-06-2002 05:11 AM

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

All times are GMT -5. The time now is 07:48 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