LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   apache default virtual host (https://www.linuxquestions.org/questions/linux-software-2/apache-default-virtual-host-777550/)

rs232 12-22-2009 05:38 PM

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

routers 12-23-2009 12:56 AM

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>


rs232 12-23-2009 02:18 AM

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

routers 12-23-2009 02:54 AM

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

rs232 12-23-2009 04:46 PM

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 :-)

routers 12-23-2009 08:57 PM

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


All times are GMT -5. The time now is 07:44 AM.