Score:0

Default Apache Named VirtualHost when Visiting by IP

ru flag

I originally had the following httpd.conf setup:

<VirualHost *:80>
  ServerName MainDomain.com
  ServerAlias Alternate1.com Alternate2.com etc...
  DocumentRoot /var/www/MainSite
...
...
</VirtualHost>

<VirualHost *:443>
  ServerName MainDomain.com
  ServerAlias Alternate1.com Alternate2.com etc...
  DocumentRoot /var/www/MainSite
  SSLEngine on
  ...
  ...
  ...
</VirtualHost>

I also had ssl.conf as follows

...
...    
<VirtualHost _default_:443>
  DocumentRoot "/var/www/DefaultSite"

  SSLEngine on
  ...
  ...
  ...
  
</VirtualHost>

In the above configuration, Visiting both http and https versions of MyDomain.com and any aliases, it worked as expected. If I visited the server by https://IPADDRESS, MainSite was returned, while http://IPADDRESS retunred "The requested URL / was not found on this server."

I need both http://IPADDRESS & https://IPADDRESS to return DefaultSite instead.

so in ssl.conf VirtualHost I added:

ServerName IPADDRESS:443

and added a new section to httd.conf

<VirtualHost _default_:80>
  ServerName IPADDRESS
  DocumentRoot /var/www/DefaultSite/
</VirtualHost>

Now MainDomain.com and all aliases are working as before with the new added functionality of http://IPADDRESS & https://IPADDRESS both resolve to the DefaultSite

I have 2 questions regarding this jounrney.

  1. Why was visiting https://IPADDRESS resolving to MainDomain.com with the original configuration?

  2. Is my current solution the proper / generally accepted way to make this work as I need?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.