Handling DNS with Rapp

Handling DNS

You can change the DNS your Application responds to at any given time. That’s done using the change_dns command.

Here’s how it’s used:

$ wn change_dns rubyista.info
[Webbynode] Changing DNS to rubyista.info...
            Creating DNS entries for www.rubyista.info and 
              rubyista.info...
            Your application will start responding to rubyista.info 
              after next deployment.

Note that, if you use a domain, it will setup both domain.com and www.domain.com. Now with a subdomain, that won’t happen:

$ wn change_dns subdomain.rubyista.info
[Webbynode] Changing DNS to subdomain.rubyista.info...
            Creating DNS entry for subdomain.rubyista.info...
            Your application will start responding to 
              subdomain.rubyista.info after next deployment.

And next time you push your app, it will start responding to this new DNS entry.

Wildcards

Important: Wildcards support require Webbynode gem version 1.0.3 or greater

For applications that uses subdomains, a wildcard domain may be necessary. To use a wildcard DNS with Rapp, just change the DNS using “*.yourdomain.com”, like this:

$ wn change_dns \*.rubyista.com
[Webbynode] Changing DNS to *.rubyista.com...
Creating DNS entry for *.rubyista.com...
Your application will start responding to 
  *.rubyista.com after next deployment.

Next time you push your app you will note the following output:

$ wn push
[Webbynode] Pushing r3app
Counting objects: 146, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (122/122), done.
Writing objects: 100% (146/146), 94.78 KiB, done.
Total 146 (delta 34), reused 0 (delta 0)
remote: Checked out master branch
remote: 
remote: ----------------------------
remote:   Webbynode git deployment 
remote: ----------------------------
remote: 
remote: Apache webserver detected...
remote: Deploying application r3app as *.rubyista.com...
remote: 
remote: Configuring addons...
remote: 
remote: Configuring Rails 3 application...
remote:   => Configuring apache vHost...
remote:      Setting up wildcard alias...
(...)

After that, your application will start responding to anything that ends with the domain you specified, in this case rubyista.com.

Aliases

Important: This feature is currently available using the beta5 version of our gem only. To install, use gem install --pre webbynode.

You can manage the DNS aliases of an application using the dns_aliases command:

$ wn help dns_aliases
Changes the DNS aliases for this application
Usage: webbynode dns_aliases [action] [alias]
Parameters:
    action              add, remove or show, optional
    alias               alias, optional

The default action is to list your aliases:

$ wn dns_aliases
No current aliases. To add new aliases use:

  wn dns_aliases add new-dns-alias

You can also add new aliases:

$ wn dns_aliases add subdomain.mywebsite.com
Alias subdomain.mywebsite.com added.
Current aliases: subdomain.mywebsite.com

$ wn dns_aliases add subdomain2.mywebsite.com
Alias subdomain2.mywebsite.com added.
Current aliases: subdomain.mywebsite.com subdomain2.mywebsite.com

And remove them:

$ wn dns_aliases remove subdomain2.mywebsite.com
Alias subdomain2.mywebsite.com removed.
Current aliases: subdomain.mywebsite.com

By default, when you push your application, we don’t recreate your vhosts file. This happens because we want to allow our users to customize their vhosts and prevent overwriting those customizations every time an user uses the wn push command.

In order to make the server aknowledge your new aliases, you have to push using the --recreate-vhost option. Note the message below indicating the recreation of the vhost file:

$ wn push --recreate-vhost 
[Webbynode] Pushing r3app
Counting objects: 9, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 467 bytes, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: HEAD is now at af5dfdb x
remote: 
remote: ----------------------------
remote:   Webbynode git deployment 
remote: ----------------------------
remote: 
remote: Apache webserver detected...
remote: Deploying application r3app as mywebsite.com...
remote: 
remote: Configuring addons...
remote: 
remote: Configuring Rails 3 application...
remote:   => Configuring apache vHost...
remote:      Recreating vhost with aliases: subdomain.mywebsite.com...
remote:   => Configuring database...
remote:   => Bundling gems...
remote:   => Migrating database...
remote: /var/rapp/r3app
remote: 
remote: Restarting apache
remote: 
remote: r3app deployed successfully.
remote: 
To ssh://git@67.23.79.85:22/var/rapp/r3app
   760c838..af5dfdb  HEAD -> master

[Webbynode] Finished pushing r3app

From this point, all your aliases should be reflected on the server.

Redirection

If you’re using nginx and you want to redirect one domain to another, take a look at this guide.

Comments
blog comments powered by Disqus