Avatar of Colin Brazier
Colin BrazierFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

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

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

Apache Web Server

Avatar of undefined
Last Comment
Colin Brazier
Avatar of giltjr
giltjr
Flag of United States of America image

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?
Avatar of Colin Brazier
Colin Brazier
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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?
Avatar of Colin Brazier
Colin Brazier
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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

Avatar of giltjr
giltjr
Flag of United States of America image

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
Avatar of Colin Brazier
Colin Brazier
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

www.refactor.com resolves to67.222.132.198

 IP address of my Apache server 192.168.0.3
Avatar of giltjr
giltjr
Flag of United States of America image

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.
Avatar of Colin Brazier
Colin Brazier
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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.
Avatar of giltjr
giltjr
Flag of United States of America image

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
Avatar of Colin Brazier
Colin Brazier
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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
Avatar of giltjr
giltjr
Flag of United States of America image

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.
Avatar of Colin Brazier
Colin Brazier
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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?
Avatar of giltjr
giltjr
Flag of United States of America image

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
Avatar of Colin Brazier
Colin Brazier
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of giltjr
giltjr
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Colin Brazier
Colin Brazier
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Ok, thanks.  All fine now.  I really appreciate your help and patience.
Apache Web Server
Apache Web Server

The Apache HTTP Server is a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards. Typically Apache is run on a Unix-like operating system, but it is available for a wide variety of operating systems, including Linux, Novell NetWare, Mac OS-X and Windows. Released under the Apache License, Apache is open-source software.

21K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo