VirtualHost with both IP and ServerName?
Posted by: pixeldroid (---.mdsnwi.dsl.dynamic.tds.net)
Date: September 12, 2019 11:39PM

When I assign an IP to a virtual host, I see that visiting the assigned servername (http://serverName) will display the same page as localhost. Is that the expected behavior? Is there way to use either/or to visit the site?

For example, using the virtual host defined below (a WordPress install), I can visit 127.0.0.12 but [mywptest] opens the same page as localhost.
Thanks.

<VirtualHost 127.0.0.12:80>
ServerName mywptest
DocumentRoot "d:/_tmp/_supertmp/wptest03"
<Directory "d:/_tmp/_supertmp/wptest03/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>

Options: ReplyQuote
Re: VirtualHost with both IP and ServerName?
Posted by: RiggsFolly (Moderator)
Date: September 13, 2019 12:13AM

Hello,
Can you also show us your Hosts file please.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.1.8 32bit & 64bit)
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.16>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your MySQL databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: VirtualHost with both IP and ServerName?
Posted by: pixeldroid (---.mdsnwi.dsl.dynamic.tds.net)
Date: September 13, 2019 01:42PM

#
127.0.0.1 localhost
::1 localhost

127.0.0.1 headlessTest01
::1 headlessTest01

127.0.0.12 mywptest
::1 mywptest

Options: ReplyQuote
Re: VirtualHost with both IP and ServerName?
Posted by: RiggsFolly (Moderator)
Date: September 13, 2019 02:51PM

Hi,

I admit I am not an expert in this area, but I think this is to do with the difference between IPV4 and IPV6 loopback addresses and the way browsers decide which range (IPV4 or IPV6) to use.

127.0.0.1 to 127.255.255.254 are all considered loopback addresses but only ::1 in the IPV6 range is a loopback address.

Mix this with the fact that your browser will likely pick an IPV6 route over an IPV4 route this explains it.

If you use `[127.0.0.12]` it will force the browser to use IPV4 and that will load the proper site because it finds this line `127.0.0.12 mywptest` in your HOSTS file or rather the DNSCache.

If however you enter `[mywptest]` the browser will likely choose to use IPV6, that will mean it will see your HOSTS file line `::1 mywptest` and as `::1` indicates a loopback you get back to localhost.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.1.8 32bit & 64bit)
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.16>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your MySQL databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: VirtualHost with both IP and ServerName?
Posted by: pixeldroid (---.mdsnwi.dsl.dynamic.tds.net)
Date: September 13, 2019 03:40PM

Hmm.
That is intesting. When I visit `headlessTest01` (don't even need []), the browser delivers that site. When setting up the VH for that domain, I didn't specify an IP. How does that work in the IPV4 vs IPV6 mechanism?

Looking that settings in conf and hosts, I would think that, if nothing else, `127.0.0.1/mywptest` would work, but it throws a 'not found' error.

This isn't a big deal, I just like to know the capabilities of my tools...

The rest of my conf:

# Virtual Hosts
#
<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
  </Directory>
</VirtualHost>


#
<VirtualHost *:80>
	ServerName headlessTest01
	DocumentRoot "d:/artstuff/webstuff/jscript/react/headlesstest01"
	<Directory  "d:/artstuff/webstuff/jscript/react/headlesstest01/">
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		AllowOverride All
		Require local
	</Directory>
</VirtualHost>


#
<VirtualHost 127.0.0.12:80>
	ServerName mywptest
	DocumentRoot "d:/_tmp/_supertmp/wptest03"
	<Directory  "d:/_tmp/_supertmp/wptest03/">
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		AllowOverride All
		Require local
	</Directory>
</VirtualHost>



Edited 1 time(s). Last edit at 09/16/2019 11:40AM by RiggsFolly.

Options: ReplyQuote


Sorry, only registered users may post in this forum.