Solved

Name-based hosting...serveralias goes to external site with same name

Posted on 2014-12-05
15
88 Views
Last Modified: 2014-12-08
OK, I have been away from this project for a couple of years, so am a bit rusty.  But...

Below is an extract from my httpd-vhosts.conf file (and it is included in httpd-vhosts.conf).

When I enter www.refactor.com in my browser, I expect my named host to take preference over the real external site of that name, but it doesn't.  Where am I going wrong please?

# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "E:/xampp/htdocs"
    <Directory "E:/xampp/htdocs">
	Options +Indexes FollowSymLinks +ExecCGI +Includes
	AllowOverride AuthConfig FileInfo
	Order allow,deny
	Allow from all
	</Directory>
</VirtualHost>

## My first domain ##

<VirtualHost *:80>
    ServerName myfirstdomain.com
    ServerAlias www.myfirstdomain.com
    DocumentRoot "E:/xampp/htdocs"
</VirtualHost>

## My second domain for refactoring the FOBG site ##

<VirtualHost *:80>
    ServerName refactor
    ServerAlias www.refactor.com
    DocumentRoot "E:/xampp/htdocs2"
    <Directory "E:/xampp/htdocs2">
	Options +Indexes FollowSymLinks +ExecCGI +Includes
	AllowOverride AuthConfig FileInfo
	Order allow,deny
	Allow from all
	</Directory>
</VirtualHost>

Open in new window

0
Comment
Question by:colinspurs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 57

Expert Comment

by:giltjr
ID: 40482802
What do you mean by "the real external site of that name"?

If everything is setups correctly you see see whatever is located at "E:/xampp/htdocs2"

1) You need named virtual host configured correctly.
2) The host name www.refactor.com needs to point to the IP address that Apache is listening on.

So, if you do "nslookup www.refactor.com" does it return the IP address that your server is listening on?
0
 
LVL 3

Author Comment

by:colinspurs
ID: 40483012
Thanks for replying.

I want to see see whatever is located at "E:/xampp/htdocs2".  Instead I see www.refactor.com (actually it redirects to http://refactor.com.au/

So everything can't be set up correctly.

 I think we need to go back to basics here...how do I know what IP address Apache is listening on?
0
 
LVL 3

Author Comment

by:colinspurs
ID: 40483022
I don't think it's set to specific IP addresses?
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 0.0.0.0:80
#Listen [::]:80
Listen 80

Open in new window

0
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 
LVL 57

Expert Comment

by:giltjr
ID: 40483437
Again, what IP address does www.refactor.com  reslove to?
     Issue command: nslookup www.refactor.com 


What is the IP address of your Apache server?  
If Windows issue the command: ipconfig
If *inx issue the command : ifconfig
0
 
LVL 3

Author Comment

by:colinspurs
ID: 40483520
www.refactor.com resolves to67.222.132.198

 IP address of my Apache server 192.168.0.3
0
 
LVL 57

Expert Comment

by:giltjr
ID: 40483796
O.K., then your Apache server is not the web  server that is hosting www.refactor.com.

Are you trying to setup a test site for www.refactor.com?

If so, then in your hosts files you can code:

192.168.0.3 www.refactor.com

Your hosts file is MOST likely located at C:\windows\system32\drivers\etc.  Depending on which version of Windows you are running you will have to edit as Admin.  Just remember if you want to go to the "real" www.refactor.com, you will need to comment out the line above in your hosts file.
0
 
LVL 3

Author Comment

by:colinspurs
ID: 40485561
I cannot find the hosts file.  There is no etc folder.

Yes I am trying to set up a test environment which I have successfully done before.

I am running Windows 7.
0
 
LVL 57

Expert Comment

by:giltjr
ID: 40485608
You need admin authority on your PC.  Issue the command:

cd "%windir%\system32\drivers\etc"

and then look for the file hosts.  There is no suffix on the hosts file, the full file name is just plain hosts
0
 
LVL 3

Author Comment

by:colinspurs
ID: 40485629
Ok thanks...all my test environments are there, with 127.0.0.1  as IP address...I'll change them all to 192.168.0.3

Would my IP address ever change?

# localhost name resolution is handled within DNS itself.
#      127.0.0.1       localhost
      127.0.0.1       refactor
      127.0.0.1       oop
      127.0.0.1       cljs
      127.0.0.1       fobgnew
      127.0.0.1       cl
0
 
LVL 57

Expert Comment

by:giltjr
ID: 40485648
Unless you have Apache on your PC to specifically listen on 192.168.0.3 you can leave 127.0.0.1 (local loopback address).

I would assume your PC gets its address using DHCP, which mean your 192.168.0.3 address could change, so I would continue to use 127.0.0.1.
0
 
LVL 3

Author Comment

by:colinspurs
ID: 40486422
So it's a puzzle then....  hosts is correct, httpd-vosts.conf and httpd.conf all look in order...what's my next step d'you think?
0
 
LVL 57

Expert Comment

by:giltjr
ID: 40486458
Hosts does NOT look correct to me.  You have

127.0.0.1       refactor

That means the host name "refactor" will reslove to 127.0.0.1.  You need:

127.0.0.1 www.refactor.com
0
 
LVL 3

Author Comment

by:colinspurs
ID: 40486518
You always surprise me with the speed of your response!

Ok, I think I have it now...hosts resolves to the server name, not serveralias as I thought.  So I don't need serveralias at all?
0
 
LVL 57

Accepted Solution

by:
giltjr earned 500 total points
ID: 40486590
I don't know about that. Servalias does have it place.  However typically I would expect to see something more like:

    ServerName refactor.com
    ServerAlias www.refactor.com
   
Or

    ServerName www.refactor.com
    ServerAlias refactor.com

You should never have just a "single" level name coded for ServerName or ServerAlias.   You should have either the domain name or a fully qualified host name.   In the above examples the domain name is refactor.com and the host name is www, the fully qualified host name is www.refactor.com.  

The way you had "refactor" coded in your hosts file, that would be a host name.  When Windows, actually any OS, goes to lookup that host name it would look in the hosts file first.  If it is not in the host files it will start appending domain names to the end based on the domain name search order list.  In Windows these are option in the DNS tab on Advanced networking configuration of the NIC.

With the way  you HAD your hosts file configured you should have been able to ether http://refactor and get your test page, but anything else would not have matched anything in your hosts file, so it would have go through normal DNS resolution.
0
 
LVL 3

Author Comment

by:colinspurs
ID: 40486711
Ok, thanks.  All fine now.  I really appreciate your help and patience.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Configuring Apache Camel to send and recieive from QPID Broker 2 34
Hosting application in Apache and Tomcat 1 121
LAMP problem identifier tool ? 9 127
Virtual host in apache 31 108
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question