Using an /etc/hosts file for custom domains during development

You may want to review a website with a custom domain name before the domain is publicly mapped to the website. For example, a domain name will often be routed to a live site while development is ongoing on a separate server.

Before the website is made public, you can view a development or prelaunch website with a custom domain name by modifying the /etc/hosts file on your local machine to point the custom domain name to the IP address of the environment you want to test. The /etc/hosts file contains a mapping of IP addresses to URLs. Your browser uses entries in the /etc/hosts file to override the IP-address-to-URL mapping returned by a DNS server. This is useful for testing DNS (domain name system) changes and the SSL configuration before making a website live.

Editing your /etc/hosts file on a Mac

If you're using a Mac with OS X, to edit your /etc/hosts file, open a Terminal window and run the following command:

sudo nano /private/etc/hosts

You may be asked for your password to edit the file. Enter your password.

You can now add entries to the file.

Editing your /etc/hosts file using Windows

If you're using Windows, to edit your \etc\hosts file, open [SystemRoot]\system32\drivers\etc\hosts and edit the file. (The \etc\hosts file usually exists at %windir%\system32\drivers\etc\hosts.) If the directory and file don't exist, you can create them. Some versions of Windows require that users have admin privileges to create or make changes to this file.

You can now add entries to the file.

Windows 8 file protection

Windows 8 users may have trouble editing their \etc\hosts file because Windows 8 includes file overwrite protections. For information about how to modify your \etc\hosts file in Windows 8, see How to block websites in the WIndows 8 hosts file.

Adding entries to the /etc/hosts file

Find the IP addresses for your Acquia Cloud environments on the Cloud > Domains page. Add an entry to your /etc/hosts file in the following format:

[IP address]  [URL]

For example, if your Prod environment has the IP address 12.345.678.90 and the custom domain you want to use is www.example.com, add the following line to your /etc/hosts file:

12.345.678.90    www.example.com

With this change, whenever you visit www.example.com, your browser will take you to your website's Acquia Cloud Prod environment, and not the website whose DNS record is www.example.com.

After you have configured your custom domain for your Acquia Cloud Prod environment, edit your /etc/hosts file to remove the entry.

Testing a site using SSL on an Elastic Load Balancer (ELB)

You can also use this technique to test a site using SSL on an Elastic Load Balancer (ELB). If you ping the ELB, it will return one or more IPs. Choose one of these to put into your hosts file. Requests from the browser will now resolve to one of the ELB servers currently being used. You may now test the validity of the domain against the SSL certificate being used. It is not safe to use this long term because the ELB IPs are dynamic and may change at any point, but for testing it will work, as long as the ELB continues to use the IP you selected.

For example, if 123.123.123.123 dev.mysite.com is in /etc/hosts, and try to go to http://dev.mysite.com/brochures/ and download customers.pdf, the download will fail because the request is aimed at dev.mysite.com/brochures/customers.pdf, but the actual address is mysite.prod.acquia-sites.com/brochures/customers.pdf. Removing the testing lines from /etc/hosts or adding the development site to DNS will correct this problem.

Contact supportStill need assistance? Contact Acquia Support