Rails subdomains for different evironments - ruby-on-rails

I have a rails app, that I am currently shifting to production. But I want to setup a subdomain such that,
if I goto :
dev.myapp.com , I reach the development environment & if I goto
prod.myapp.com , I reach the production environment
Will I have to use 2 instances for this purpose, or can this managed by one?
My servers are on AWS, and domain is managed by GoDaddy

You can definitely use both environments on the same server but you would have to have 2 different instances running.
You can use nginx or Apache HTTPD to route the different domains (or sub-domains) to the actual instance running on your server (if it's an AWS EC2).
You have several other ways to configure it depending on your setup.

You'll need separate instances of the application running; the choice of running environment is a global, boot-time decision, with wide-ranging effects.
It's totally possible to run both of those application instances on the same server (AWS EC2 instance)... though it's more traditional to run the development mode on a local development machine, safely distanced from production.

Related

2 Rails Apps on Same Instance

I'm trying to deploy host a production instance for my rails 4 applications. I can currently (and successfully) host them using nginx, unicorn, and capistrano.
To save money I would like to host both of my rails 4 apps on the same instance. Is it possible to host multiple production environments, which would ideally be connected to different domains?
Thanks!
You can run multiple rails applications by configuring each application to use a different unicorn socket.
You can then configure nginx sites (see /etc/nginx/sites-enabled/www.blah.com) to route to different unicorn sockets.
Have a look at these answers:
multiple rails apps on nginx and unicorn
You need two separate virtual servers on nginx.
You can find more informations here:
http://nginx.org/en/docs/http/request_processing.html

Is one rails server per application?

I have two questions about rails server:
Do I have to start the server from within the application folder?
Is the server I started only for that application?
If they are true, this does not quite make sense to me, since why do I need to start multiple servers?
Or is there some kind of master configuration, so that one server can route to different applications? Is Capistrano for this purpose?
I'm going to assume you're talking about the rails server command, for running a local rails server to test your application, and that you're not talking about setting up a rails application on a remote server. Please mention if that is not the case.
Yes, you must execute rails server from within the root folder of your rails application.
Yes, the server you started is only for that application. It's a self-contained thing.
You should not need to start multiple servers. Even if you have multiple applications, you probably don't need to have more than one running at a time. So, you can shut down the rails server in one application (Ctrl-C) and then cd to your new application, and start a new rails server there with rails server.
If you do need to run two local rails applications at once, you can do so by running them on different ports. So, the first one, you can just execute rails server and it will make your site available at localhost:3000 (because port 3000 is the default port). The next one, you can specify a port other than 3000 - eg. rails server -p 3001 to get a rails app at localhost:3001.
Capistrano is for deploying your applications to a remote server, not for running them locally on your own computer. So, it is not relevant here. What you may be interested in is http://pow.cx/
Again, I've assumed you're talking about running your rails app locally on your own computer. If you're referring to deploying it to the internet on a server, then you can ignore this answer.

How to deploy a rails app with no domain name. (trying to create a test server)

Ok so what i'm trying to do is deploy my first rails project. I've asked this question and i think i figured out that you can't configure apache to work using an ip and you have to have a domain name.
The reason i can't use the domain name yet is because i'm recreating a site for someone and they don't want it to be down in between switching the domain from their current site to their new rails site.
I'd like to get my rails app running on a server so I can test it out and then once it's ready, switch the domain name.
How can i setup a server to run a rails project without using the domain name?
If you want to run the rails project locally in development mode, then just run the command rails s from the root of your project.
It is possible to deploy two apps to the same server, or two versions of the same app, I typically use sub-domains for this, website.com and then testing.website.com.
You will just need to have seperate databases and seperate virtualhost files.
You could also try to access the apache machine by it's IP address if it is on the local network.

Deploying Rails and Nodejs

I wrote a real-time web app that consists of the following:
Rails to serve the web pages (listens on port 80)
Nodejs to handle real-time logic (listens to port 8888)
So on a particular page served by my rails app, the JS will use socket.io to establish a connection to my nodejs instance to allow real time http push.
Currently Nodejs communicates with Rails simply by updating the rails database. (I know this is ghetto but it works).
What are my options for deployment?
I have deployed simple web apps on heroku before and I really like the simplicity.
I have also deployed a web app with similar functionality (except it's made up of django + nodejs). I used HAProxy to do reverse proxying to handle direction of traffic to the correct process on my machine. However, I deployed this on a VPS server instead.
Note: the ugliness will probably revolve around:
I am relying on a common db
These processes are listening on different ports
We had this exact issue. We deployed them to separate Heroku applications, but kept them within the same code base. http://techtime.getharvest.com/blog/deploying-multiple-heroku-apps-from-a-single-repo outlines how to do it.
Manually set the buildpack
Set a config variable that you can reuse in step #3.
Create a custom web script that your Procfile uses
A custom script in bin/web
#!/bin/bash
if [ "$RAILS_DEPLOYMENT" == "true" ]; then
bundle exec rails server -p $PORT
else
node node/index.js
fi
And the Procfile:
web: bin/web
I would consider setting these two applications up as separate Heroku applications on different subdomains and just having them both on port 80. The communication between them goes through a shared database so they don't need to reside on the same machine or even datacenter. Socket.io supports cross domain requests on all browsers, so that shouldn't cause any problems.

Deploy Ruby on Rails - Development Environment

I'm developing an small application on RoR and OSX 10.6.4 workstation, and I'm looking for guidance on two things: -
How to share my application locally with others so others in my team can get access to my local webserver (Mongrel?) to view/play with my system before I release it into production. From my default installation I can play with it both others can't seem to access it - not even from say http://:3000, which works from local - so I'm a bit confused.
Advice on how best to deploy it onto a production webserver assuming I deploy onto Linux. What webserver should I use and are there instructions?
Thanks in advance. Networking and webservers are NOT a strong suite :-)
Cheers
B
The development Mongrel is by default only accessible through localhost. In order to be visible from the outside you need to ask it to bind to your external IP address. Assuming your IP address is 10.0.0.5, you need to do this:
script/server -b 10.0.0.5
For deployment on Linux, the easiest way is perhaps using Passenger, and either Apache or nginx for a web server, whichever you're most comfortable with (if you have no preference, go with Apache). Documentation can be found here.
Why can't others access it via http://your.ip:3000/? ./script/server mongrel listens on 0.0.0.0 by default. 0.0.0.0 stands for listening on every interface in Linux.

Resources