LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache Virtual Host Annoyance (https://www.linuxquestions.org/questions/linux-server-73/apache-virtual-host-annoyance-539619/)

jmoschetti45 03-22-2007 07:29 AM

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?

bathory 03-22-2007 08:48 AM

You have to add
Code:

ServerAlias example.com *.example.com
inside your <VirtualHost>..</VirtuaHost>, assuming that www.example.com is your ServerName

Regards

jmoschetti45 03-23-2007 05:14 AM

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>

bathory 03-23-2007 05:49 AM

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>

jmoschetti45 03-23-2007 11:33 AM

The ServerName is set to radio276.com, so I don't see why it's going to jmoschetti45.com as the default page.

bathory 03-24-2007 09:54 AM

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.


All times are GMT -5. The time now is 01:50 AM.