How to stage an edge application through the hosts file

Before you point your domain to Azion, you can stage running your application on the edge by changing the name resolution of your hosts file. This way, you’ll have a chance to stage any changes and correct bugs before you publish your application using your custom domain.


Requirements

You’ll need:

  • An edge application and a configured domain.
  • A working internet connection.
  • sudo privileges in your device.
  • A command line tool, such as Windows PowerShell or Mac Terminal.
  • For Windows, a text-editing tool such as Notepad.

Step 1. Finding your edge node IP

To stage an application on the edge through the hosts file, you must redirect your device’s DNS resolution to an edge node.

First, you need to find the IPs of the edge node where your application is being served. The node IP will change based on the edge node associated with your current location.

There are several ways to find your edge node IP, but the most common one is to use the host command paired with your Azion domain.

The following command can be run on any Unix-based or Windows operating systems:

Terminal window
host xxxxxxxxxx.map.azionedge.net

You’ll receive a response containing the Azion domain and one or more IP addresses of the edge node:

Terminal window
xxxxxxxxxx.map.azionedge.net has address 200.0.0.0

Step 2. Associating the edge node IP to a domain

Now you must associate the edge node IP to one or more CNAMEs that you’ve specified for your domain in your host configuration.

Windows

  1. Launch Notepad or any other text editing tool.
  2. Open the hosts file, which should be located in C:\Windows\System32\drivers\etc\.
  • Note that the hosts file is located in whichever drive Windows was installed and thus may not be the C: drive.
  1. Add a new line under the localhost line.
  2. Paste the edge node IP into the first column.
  3. Add the CNAME you configured for the Azion domain to the second column. For example:
Terminal window
200.0.0.0 yourdomain.com
200.0.0.0 yourdomain.org
  1. Click on File > Save.

Linux

  1. Launch the terminal.
    • In most Linux distributions, the terminal is located uder Applications > Utilities > Terminal.
  2. Type the following command to launch the vim text editor:
Terminal window
sudo vim /etc/hosts
  1. Confirm your identity by typing your system password and press Enter.
  2. Use the arrow keys to navigate through the file.
  3. Add a new line under localhost.
  4. Paste the edge node IP into the first column.
  5. Add the CNAME you configured for the Azion domain in the second column.
Terminal window
200.0.0.0 yourdomain.com
200.0.0.0 yourdomain.org
  1. Press Esc to switch to command mode.
  2. Type :x and press enter to save and exit the vim terminal editor.

macOS

  1. Use the Launchpad to search for the Terminal app.
  2. Open the terminal and type the following command to launch the nano text editor:
Terminal window
sudo nano /private/etc/hosts
  1. Confirm your identity by typing your system password and press Enter.
  2. Use the arrow keys to navigate through the file.
  3. Add a new line under localhost.
  4. Paste the edge node IP into the first column.
  5. Add the CNAME you configured for the Azion domain in the second column.

For example:

Terminal window
200.0.0.0 yourdomain.com
200.0.0.0 yourdomain.org
  1. Press Ctrl+O to save your changes.
  2. Press Ctrl+X to exit the nano text editor.

Step 3. Staging your application

Once your hosts file is configured, you’ll be able to access your application through the CNAMEs you provided using any browser in your device.

To avoid your browser from resolving your host name through cache, launch your browser using incognito mode, use a different browser, or clear browser cache before accessing the domain.

In the absence of cache, if your original application is already served on the CNAME you assigned but hasn’t undergone domain record modifications in the DNS provider, the hosts file will serve the edge application using the custom host.

To access your staged application through a browser, in the search bar, navigate to the same CNAME you configured in your domain and in the hosts file.

You should now see your Azion domain as if it was in production and perform any necessary tests before pointing your DNS resolution from your provider or migrating your authoritative nameservers to Azion.


Contributors