OSX does have a /etc/hosts file but it first uses directory services to find hosts. These are maintained via the dscl command
This web page provides examples of use to maintain the lookups.
Essentially, you just need to run the following command in Terminal:
sudo dscl localhost -create /Local/Default/Hosts/sitename.com IPAddress 127.0.0.1
Map x.com/staging to another server
Assuming you're running on Apache, proxying might do the trick. Running a Reverse Proxy in Apache suggests the following might work, but I did not test it:
ProxyPreserveHost on
ProxyPass /staging/ http://y.y.y.y/
ProxyHTMLURLMap http://y.y.y.y /staging
<Location /staging/>
ProxyPassReverse /
ProxyHTMLEnable On
ProxyHTMLURLMap / /staging/
# We need to peek into the HTML, so ensure we don't get gzip'd content:
RequestHeader unset Accept-Encoding
</Location>
Above, a virtual folder /staging
maps all from http://x.com/staging/
to /
on the other IP address. To still keep using x.com
as the host, I added ProxyPreserveHost.
All this will need the trailing slash; some standard rewriting could add that when needed:
# Add trailing slash if omitted
RewriteRule ^staging$ /staging/ [R=302,L]
Avoid sharing cookies: use a dedicated domain
However, to avoid very nasty problems with session cookies, I'd prefer a dedicated domain (preferably not even some subdomain of x.com
). For that, remove all references to staging
above. And to still send the expected domain name, I assume one could add an additional:
RequestHeader set Host x.com
When using such dedicated domain then Apache also won't have to rewrite any relative URLs, such as /some/page
into /staging/some/page
. However, this might imply you won't notice failures in rewriting absolute URLs (especially possible when JavaScript is involved). Like a failure to rewrite http://x.com/some/page
back into http://client.mycompany.com/some/page
might go unnoticed if the same URL exists on the production server, and the browser fetches that directly. That might be a benefit, or could be a disaster when you're still logged in to the production server and think you're changing content on the staging server...
Using .htaccess
Just for posterity, earlier I figured one could also use something like the following in a .htaccess
file:
# Does NOT work (for me). On the target server, this gets me:
# HTTP_HOST = y.y.y.y - from the proxy request? Expected x.com
# HTTP_X_FORWARDED_HOST = x.com - from Host
# HTTP_X_MY_DUMMY = x.com - from X-My-Dummy, as expected
RewriteEngine On
RequestHeader set Host x.com
RequestHeader set X-My-Dummy x.com
RewriteRule ^(.*) http://y.y.y.y/$1 [L,P]
ProxyPassReverse / http://y.y.y.y/
However, ProxyPassReverse
does not seem to be allowed in .htaccess
. And some basic testing seems to reveal that the [P]
proxy also always adds its own Host
header, and translates my Host
into X-Forwarded-Host
. This could very well be related to the shared virtual hosting that I used for some quick test. But ProxyPreserveHost
cannot be used in .htaccess
.
See Apache's mod_proxy, mod_headers and mod_rewrite documentation.
Best Answer
The "duplicate name exists" error is because the (NetBIOS) name of the Windows computer conflicts with some other name on the network. The instructions tell you how to resolve the issue - Go to System in Control Panel to change the computer name and try again.
You need to change your computer's name since windows won't allow PCs to have the same name in the same workgroup.
You will need to reboot to flush everything out.