How to transfer my domain to my rails application?

May 14, 2016 284 views
Deployment Ruby on Rails DNS Nginx

I am trying to transfer my domain. I am running my rails app using this command from my rails folder
RAILS_ENV=production rails s --binding=
However, I can only access it through but not

I might be wrong but I think I need to somehow serve my app from the root domain address like not I have already point my domain name to DigitalOcean by following this tutorial And I have also setup the host name with DigitalOcean. So right now I just need to configure rails, nginx, and unicorn somehow to serve my app at the domain address or (I don't even know if that is what I need to do. so please help me!)

I am running Ubuntu 14.04 with rails, nginx, and unicorn. I've configured my nginx and unicorn according to this tutorial here

How do I make rails application accessible from the root of the domain address ( or is that eve necessary at all?

How exactly do I deploy my rails application? I am lost! Please help!

1 Answer

You need to use nginx to proxy HTTP requests to whatever port unicorn is running on. In this specific case that is port 3000.

When you go to any website using a web browser by default is actually just sending a request to the IP address at on port 80. Likewise, when you go to it is sending a request to that IP address at on port 443.

So, in your case you have unicorn running on port 3000, and you need to get nginx to listen on port 80 and proxy all requests to port 3000.

  1. SSH into your server
  2. Edit the nginx config file nano /etc/nginx/sites-available/default
  3. Replace everything in there with this:

    server {
    listen 80;
    location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  4. Restart nginx service nginx restart

You should now be able to access your rails app at both and assuming you have an A record for YOUR_WEBSITE.COM pointed to then you should also be able to access the app at http://YOUR_WEBSITE.COM

Hope this helps!

Have another answer? Share your knowledge.