Using xip.io to point domain to any host


Posted:   |  More posts about dns nginx

When I first heard about it from Armin Ronacher's twitter status last year, I don't really get what problem it solve and how it can be useful.
Working with a number of virtual instances from vagrant launched virtual machines or lxc container to instance of aws ec2 or digital ocean's droplet, all with varying IP address, I started to value something like xip. My /etc/hosts now has 90+ entries, some of it not used anymore. Everytime I have new instance to test with my app, I have to add new entry in /etc/hosts to point to that IP, and then forgot about it.

xip.io simply resolve any subdomain of it to the ip address included as part of the subdomain. For example let say you have an app running at server with IP address 10.0.0.1. The app has been configured to serve a domain called dev.myapp.com (using virtual host of the webserver). So that you can access the app using http://dev.myapp.com, you have to add in /etc/hosts the ip address of the server. Since dev.myapp.com is for development and it can be on any machine, adding it to your real dns server does not make sense so /etc/hosts a good fit for it. But that mean your /etc/hosts will quickly grow with list of entries that you might only use once.

So instead adding the IP to /etc/hosts, let xip.io resolve it. We can define the domain for xip.io as subdomain.[ip-address].xip.io and it will resolve to that [ip-address]. For example:-

dev.myapp.com.10.0.0.1.xip.io      --------> 10.0.0.1
dev.myapp.com.192.168.0.1.xip.io   --------> 192.168.0.1
dev.myapp.com.124.108.16.53.xip.io --------> 124.108.16.53
test.myapp.com.127.0.0.1.xip.io    --------> 127.0.0.1

To actually serve the above sites, we have to change our web server config a bit so it can consider the above willcard. For example, for nginx, the config should look like:-

server {
        root /usr/share/nginx/dev;
        index index.html index.htm;

        server_name ~^dev\.myapp\.com\.(.*)\.xip\.io$;
        ...
        ...
}

This kind of service, coupled with others such as localtunnel or pagekite would be really helpful and as Armin said in the tweet, should in every developers toolbox.

Comments powered by Disqus

About me

Web developer in Malaysia. Currently work at MARIMORE Inc building internet services using Python and Django web framework.

ImportError is an error message emitted by Python when it failed to load certain module as requested by programmer. It's a very common error when someone new to the language trying it out. This website on the same theme, will try provide help for newcomers on any technologies to overcome their first hurdle.

Try most of the examples you may find here on Digital Ocean cloud service. They provide excellent VPS at a very cheaper price. Using this referral link you'll get USD10 credits upon sign up. That's enough to run single VPS with 1GB RAM for a month.

Others

I can also be found at the following sites:-

  • http://k4ml.blogspot.com/
  • http://k4ml.github.io/
  • http://metak4ml.blogspot.com/
  • http://www.mydev.my/
  • http://github.com/k4ml/

Disclaimers

The postings on this site are my own and don't necessarily represent my employer's positions, strategies or opinions.

Share