How to stage an 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 application and a configured domain.
- A working internet connection.
sudoprivileges 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:
host xxxxxxxxxx.map.azionedge.netYou’ll receive a response containing the Azion domain and one or more IP addresses of the edge node:
xxxxxxxxxx.map.azionedge.net has address 200.0.0.0Step 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
- Launch Notepad or any other text editing tool.
- Open the
hostsfile, which should be located inC:\Windows\System32\drivers\etc\.
- Note that the
hostsfile is located in whichever drive Windows was installed and thus may not be the C: drive.
- Add a new line under the
localhostline. - Paste the edge node IP into the first column.
- Add the CNAME you configured for the Azion domain to the second column. For example:
200.0.0.0 yourdomain.com 200.0.0.0 yourdomain.org- Click on File > Save.
Linux
- Launch the terminal.
- In most Linux distributions, the terminal is located uder Applications > Utilities > Terminal.
- Type the following command to launch the
vimtext editor:
sudo vim /etc/hosts- Confirm your identity by typing your system password and press Enter.
- Use the arrow keys to navigate through the file.
- Add a new line under
localhost. - Paste the edge node IP into the first column.
- Add the CNAME you configured for the Azion domain in the second column.
200.0.0.0 yourdomain.com 200.0.0.0 yourdomain.org- Press Esc to switch to command mode.
- Type
:xand press enter to save and exit thevimterminal editor.
macOS
- Use the Launchpad to search for the Terminal app.
- Open the terminal and type the following command to launch the
nanotext editor:
sudo nano /private/etc/hosts- Confirm your identity by typing your system password and press Enter.
- Use the arrow keys to navigate through the file.
- Add a new line under
localhost. - Paste the edge node IP into the first column.
- Add the CNAME you configured for the Azion domain in the second column.
For example:
200.0.0.0 yourdomain.com200.0.0.0 yourdomain.org- Press Ctrl+O to save your changes.
- Press Ctrl+X to exit the
nanotext 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 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.