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
Related
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.
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.
I would like to discuss about AngularJS and Ruby on Rails working together and deployed in AWS (Amazon Web Services).
So far, I have a development environment with an AngularJS frontend that sends request to a Ruby on Rails API backend. These both are two separate applications (they are in separated git repositories).
The AngularJS app is running in a Node.js server listening on one port, and Rails is running in a Webrick server listening on another port.
Although they work together, AngularJS is not physically integrated in the RoR app.
Now its time to deploy in production environment. For that, I will use an EC2 AWS instance (currently deploying using Elastic Beanstalk). As far as I understand, I can't have the same architecture here.
I would like to know your suggestions this point. Do you see any advantages or disadvantages?
Should I update my development environment, so the AngularJS app is integrated inside the RoR application (and deploy just one application)?
This is something I don't like, because I guess I have to modify many things.
On the other hand, is it possible to run both applications separately, the same way I do in development?
Can I install a node.js and a Unicorn or whichever server manually in production in the same instance?
I finally deployed with two separated applications as described above. The main difference is around the servers. My AngularJS frontend finally runs on an Nginx. And my Rails API is running on a Unicorn.
I have rails app running on unicorn+nginx. Now i wanted to deploy another small sinatra app sub uri(localhost:3000/test). Same requirement i achieved on passenger+nginx combination.
Deploying a rails app to a sub uri with passenger and nginx
Any suggestion will be appropriated.
I am assuming that you already know hoe to setup Ngnix with one Unicorn.
There are now fundamentally two ways you can do what you need.
Approach 1
Run another Unicorn (different folder, different port). For the URL pattern, setup another location in Nginx and set proxy directive to this Unicorn instance.
Approach 2
If you want to run both of these application in the same Ruby process, Rack can be used to send a set of URL patterns to Sinatra Application and rest to your Rails Application. If you are using Rails 3, you can do this in your routes.rb as well.
Please let me know if you need sample code for any of these approaches.
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.