LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-22-2009, 05:38 PM   #1
rs232
Member
 
Registered: Oct 2005
Posts: 51

Rep: Reputation: 0
apache default virtual host


Hello,
how do I define the default virtual host to be served on port 80?

I have different configuration files in /etc/httpd/conf.d/ that look more or less like this:

<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DirectoryIndex index.php index.html index.htm
ServerSignature email
DocumentRoot /var/www/mydomain.com/
</Virtualhost>

plus I have the

namevirtualhost:80
in httpd.conf


for some reason if I connect to port 80 using the IP address or an alias not defined anywhere in apache config, the first domain configured (first alphabetically a-to-z) answers the call.

Is there any way to overwride this and set a default site?

Basically I'd like to answer with the right configuration if a precise site pre-configured is called on port 80, but if not I would like to redirect to a "default site"

I hope I've explained myself :-p

Thanks for reading
rs232
 
Old 12-23-2009, 12:56 AM   #2
routers
Member
 
Registered: Aug 2005
Location: Malaysia - KULMY / CNXTH
Distribution: Slackware, Fedora, FreeBSD, Sun O/S 5.10, CentOS
Posts: 787
Blog Entries: 6

Rep: Reputation: 75
everything you have is already correct, what you need
is just add this on the top of your
<VirtualHost> as below

---------------------
Code:
namevirtualhost:80


<VirtualHost *:80>
        ServerName domain.serverhostname.com
        DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DirectoryIndex index.php index.html index.htm
ServerSignature email
DocumentRoot /var/www/mydomain.com/
</Virtualhost>
 
Old 12-23-2009, 02:18 AM   #3
rs232
Member
 
Registered: Oct 2005
Posts: 51

Original Poster
Rep: Reputation: 0
I did try this before but no luck.

basically every virtual server has a file into conf.d with a generic


<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DirectoryIndex index.php index.html index.htm
ServerSignature email
DocumentRoot /var/www/mydomain.com/
</Virtualhost>


Where the main virtual host has its own file still in conf.d in the format:

<VirtualHost *:80>
ServerName domain.serverhostname.com
DocumentRoot /var/www/html
</VirtualHost>


I'm wondering about 2 things now.
1) shell I add the
<VirtualHost *:80>
ServerName domain.serverhostname.com
DocumentRoot /var/www/html
</VirtualHost>
inside http.conf instead then conf.d/myfile?

2) the current default virtual server (which I don't want to be the default) has both ServerName directive AND file name into conf.d starting with a "d"
where the one I want to be the default has a filename (no ServerName used) starting with an "m"

Is Apache giving priority to the config file name or to the ServerName command?


Cheers
 
Old 12-23-2009, 02:54 AM   #4
routers
Member
 
Registered: Aug 2005
Location: Malaysia - KULMY / CNXTH
Distribution: Slackware, Fedora, FreeBSD, Sun O/S 5.10, CentOS
Posts: 787
Blog Entries: 6

Rep: Reputation: 75
normaly i didnt touch anything in httpd.conf
what i did is only create virtual.conf inside conf.d/

here is mine just for example

Code:
[root@ns1 ~]# cat /etc/httpd/conf.d/virtual.conf
NameVirtualHost *:80

<VirtualHost *:80>
        ServerName 115.133.137.110
        DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
       ServerName taj.edu.my
       ServerAlias www.taj.edu.my
       ServerAdmin  noc@unixman.pluto.com
       DocumentRoot /home/tajweb/www
       TransferLog /home/tajweb/logs/access-log
</VirtualHost>
FYI user directory must chmod correctly
one more thing if you check my domain its still might not get as you need
because only for development mode but its worked that way
 
Old 12-23-2009, 04:46 PM   #5
rs232
Member
 
Registered: Oct 2005
Posts: 51

Original Poster
Rep: Reputation: 0
Ok I've found the solution. What you're saying is correct but I'll add more details for reference:
My point is that I have 1 different file for each virtual server into conf.d
By default apache loads these files in order alphabetically from a to z
renaming the default one so that it becomes the first in the list does the job.
ls -la to verify

So... all I had to do was to rename mxxxxxxx into amxxxxxx this way I force apache to read it before the others.

sorted :-)
 
Old 12-23-2009, 08:57 PM   #6
routers
Member
 
Registered: Aug 2005
Location: Malaysia - KULMY / CNXTH
Distribution: Slackware, Fedora, FreeBSD, Sun O/S 5.10, CentOS
Posts: 787
Blog Entries: 6

Rep: Reputation: 75
glad you found it, in my conf.d
i have few .conf file create by hand , doesnt matter read which one first
but for sure apache will read and use all .conf file inside that conf.d folder

cheers
 
  


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
[SOLVED] Apache2 - virtual host defaulting to default host slimjim Linux - Server 1 10-31-2009 01:47 AM
IP and Domain resolving to default virtual host DropHit Linux - Newbie 4 11-19-2005 02:42 PM
Apache 2 Virtual host eckertc1 Linux - Software 6 03-22-2005 09:58 PM
RH9 Apache Virtual Host Default Document jswilson Linux - Newbie 2 01-29-2004 09:27 AM
apache virtual host mimi Linux - General 1 04-06-2002 05:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:08 PM.

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