Normal and virtual host

Problems with the Linux version of XAMPP, questions, comments, and anything related.

Normal and virtual host

Postby mecheri » 02. April 2014 15:12

Hi everyone,

I want to run two websites with httpd on my centos machine.

I have configured the first one on the standard apache configuration file (i.e. etc/httpd/conf/httpd.conf), created the index.html file under /var/www/html/. Give it the URL 'www.main_page.com'


For the second one I have configured it as a virtual-host under the following directory /mywww/ and give it www.vhost.com as URL.


When I test the url www.vhost.com it points, as expected, to /mywww/index.html.
However, when I test www.main_page.com it points also to /mywww/index.html instead of /var/www/html/index.html !!?


The content of the /etc/hosts file:

192.168.122.103 www.main_page.com
192.168.122.103 www.vhost.com


Any idea ?
mecheri
 
Posts: 3
Joined: 02. April 2014 15:03
Operating System: Linux

Re: Normal and virtual host

Postby JJ_Tagy » 02. April 2014 16:59

mecheri wrote:... For the second one I have configured it as a virtual-host ...

How and where? What do your configuration files look like?
JJ_Tagy
 
Posts: 788
Joined: 30. January 2012 13:44
XAMPP version: 5.5.15
Operating System: Windows 10 Pro x64

Re: Normal and virtual host

Postby mecheri » 04. April 2014 13:13

Hi,

Thanks for your reply.

I have created it on

/etc/httpd/conf.d/vhost.conf

Here's its content:

-----------------------------------------------
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /var/www/vhost
ServerName www.vhost.com
<Directory /var/www/vhost>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/www.vhost.com-error_log
CustomLog /var/log/www.vhost.com-access_log common
</VirtualHost>
-----------------------------------------------
mecheri
 
Posts: 3
Joined: 02. April 2014 15:03
Operating System: Linux

Re: Normal and virtual host

Postby Nobbie » 04. April 2014 15:13

That does not work (as you already might found out). If you run only one host, you may configure it as the standard host in the httpd.conf file.

If you want to run more than one host, you have to use VirtualHost FOR ALL your hosts, there is no more a "standard host", the corresponding configuration in httpd.conf is IGNORED by Apache. Instead the FIRST VirtualHost becomes the default host, so if somebody requests a hostname from your server, which is not declared as a VirtualHost, Apache takes the FIRST VirtualHost declaration instead.

Instead of only one VirtualHost you must at least declare two VirtualHost, one for http://www.main_page.com and the other for http://www.vhost.com. I always recommend to declare one explicit "_defaul_" VirtualHost as very first VirtualHost, in case someone enters http://192.168.122.103 in his browser, because this is neither http://www.vhost.com nor http://www.main_page.com, but Apache will take simply the first of these two if you dont declare a default VirtualHost as first entry. In that default VirtualHost you may show an error page or whatever you want.

Most important: either there is NO VirtualHost, or ALL Hosts are VirtualHosts.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: Normal and virtual host

Postby mecheri » 05. April 2014 12:56

Thank you guys for your replies it does make sens to me know.
mecheri
 
Posts: 3
Joined: 02. April 2014 15:03
Operating System: Linux


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 7 guests