0

I have configured Apache 2.2 so that I can have 2 hosts. The problem is when I connect using the second host, the default one is loaded.

This is the vhosts.conf file:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin support@desytec.com
    DocumentRoot /var/www/proyectos/mutual/contratos/web
    ServerName contratos.mutual.dev
    ErrorLog /etc/httpd/logs/mutual-contratos-error_log
    <Directory "/var/www/proyectos/mutual/contratos/web">
       Options FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin support@desytec.com
    DocumentRoot /var/www/proyectos/spensiones/html
    ServerName biotempo.spensiones.dev
    ErrorLog /etc/httpd/logs/biotempo.spensiones.dev-error_log
    <Directory "/var/www/proyectos/spensiones/html">
       Options FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
    </Directory>
</VirtualHost>

And this is the "httpd -S" command output:

[root@orahost conf.d]# httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443          localhost.localdomain (/etc/httpd/conf.d/ssl.conf:81)
*:80                   is a NameVirtualHost
         default server contratos.mutual.dev (/etc/httpd/conf.d/vhosts.conf:3)
         port 80 namevhost contratos.mutual.dev (/etc/httpd/conf.d/vhosts.conf:3)
         port 80 namevhost biotempo.spensiones.dev (/etc/httpd/conf.d/vhosts.conf:16)
Syntax OK
[root@orahost conf.d]# 

To test, from a remote computer I try to load biotempo.spensiones.dev but the default server is displayed.

Any help, please?

jstuardo
  • 155
  • 1
  • 7

1 Answers1

1

You can give a try with below. I had solved the problem by using below in httpd.conf.

NameVirtualHost Server_IP_Address:80

<VirtualHost Server_IP_Address:80>

........

</VirtualHost>

Let us know if you are still facing issues.

EDIT: NOTE

The asterisks * match all addresses, so the main server serves no requests. Due to the fact that the virtual host with ServerName contratos.mutual.dev is first in the configuration file, it has the highest priority and can be seen as the default or primary server. That means that if a request is received that does not match one of the specified ServerName directives, it will be served by this first .

The above configuration is what you will want to use in almost all name-based virtual hosting situations. The only thing that this configuration will not work for, in fact, is when you are serving different content based on differing IP addresses or ports.

You may replace * with a specific IP address on the system. Such virtual hosts will only be used for HTTP requests received on connection to the specified IP address. However, it is additionally useful to use * on systems where the IP address is not predictable - for example if you have a dynamic IP address with your ISP, and you are using some variety of dynamic DNS solution. Since * matches any IP address, this configuration would work without changes whenever your IP address changes.

Sachin Singh
  • 171
  • 1
  • 8
  • I have used IP of the server but the same problem occured. Then, instead of using server IP I used loopback IP 127.0.0.1 and that way, the site in DocumentRoot folder was displayed, instead of site in folder specified in virtual host configuration. – jstuardo Jul 22 '16 at 14:48
  • Putting 127.0.0.1 will always list the directories in default doc root.can you try commenting the Default Document root variable specified in httpd.conf, apart from individual virtualhosts. and specifying server ip in each virtualhost as well as Namevirtualhost. and needless to say do not forget to restart httpd after each change and clear your browser cache. – Sachin Singh Jul 22 '16 at 14:58
  • All that tries did not work. Anything else could I try? – jstuardo Jul 22 '16 at 15:03
  • By default server, you mean content of contratos.mutual.dev or apache test page? – Sachin Singh Jul 22 '16 at 15:16
  • it was "contratos.mutual.dev", however, it turned out that the corresponding website was not loaded because of an error of it. I did not know if the server throws a "Service not available" error, Apache will load default site as well. – jstuardo Jul 22 '16 at 15:27