Home > database >  Xampp unable to load multiple sites
Xampp unable to load multiple sites

Time:03-17

I am working on a project using xampp server. I have more than one project. So for this I have set my httpd-vhosts like below

<VirtualHost *:8080>
  
  ServerName khpos.com
  ServerAlias www.khpos.com

  DocumentRoot "D:/xampp/htdocs/pos"


<Directory "D:/xampp/htdocs/pos">
   Require all granted
</Directory>

</VirtualHost>
 #my second site
<VirtualHost *:8080>

ServerName demopos.com
ServerAlias www.demopos.com

 DocumentRoot "D:/xampp/htdocs/demopos"


<Directory "D:/xampp/htdocs/demopos">
   Require all granted
</Directory>

</VirtualHost>

Whenever I try to hit localhost:8080/demopos it's redirecting towards .../pos

hosts file

127.0.0.1:8080      khpos.com
127.0.0.1:8080      demopos.com

How to set it

Any help would be highly appreciated

CodePudding user response:

You should change the portnumbers of the second etc. sites. Now all port addresses are on port 8080, if you change those to an other port number you should be fine.

<VirtualHost *:8080> to <VirtualHost *:{port-number}>

Where port-number is an other port-number

127.0.0.1:8080               khpos.com
127.0.0.1:{port-number}      demopos.com

CodePudding user response:

you have 2 virtual hosts defined and also the names in hosts file - so far all ok:

ServerName khpos.com
ServerName demopos.com
127.0.0.1:8080      khpos.com
127.0.0.1:8080      demopos.com

if you call khpos.com:8080 or demopo.com:8080 it should reach your correct virtual hosts.

But: if you call localhost:8080 it will match none of your virtual hosts.

In that case Apache always enters the first virtual host matching the port that you have in your conf file ignoring its server name. That is a strange behavior of Apache - in my opinion a bug. It is exactly what you observe.

For that reason I always place a dummy virtual server in front of all others that can catch all non fitting requests with a dummy message in a simple html file.

Just a hint: you have defined

DocumentRoot "D:/xampp/htdocs/pos"

so there currently is no khpos.com:8080/pos because pos is part of the root unless you create another folder pos below

  • Related