Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

development, staging, and production environments rails app

I'm creating an app that in addition to the live production environment requires a development and staging environment. The production environment is currently live and on its own VPS instance. A record:

myapp.com  1.2.3.4

The development and staging environments will be on their own VPS instance. I've configured the appropriate DNS records so each environment has its own sub-domain (A record in the myapp.com domain pointing to the dev/staging server:

dev.myapp.com 5.6.7.8
staging.myapp.com 5.6.7.8

The Nginx confix (Rails, Passenger) sets the root for each server (wild card SSL is configure in the http definition and port 80 redirects to port 443):

server {
   listen 443;
   server_name dev.myapp.com
   root /apps/myapp/dev/public
}

server {
   listen 443;
   server_name staging.myapp.com
   root /apps/myapp/staging/public
}

I'm a bit confused on the Rails side what else do I need to do to configure the environments so I can access the individual dev and staging environments by URL:

staging.myapp.com
dev.myapp.com

I know Capistrano allows you to set production and staging environments but I need both the dev and staging URLs to be live or should this be sufficient?

like image 568
cheifops Avatar asked Apr 29 '11 01:04

cheifops


People also ask

What are the environments of Rails?

Rails comes with three environments: development, test, and production, but it is easy to add your own.

Is staging environment same as production?

A staging environment (stage) is a nearly exact replica of a production environment for software testing. Staging environments are made to test codes, builds, and updates to ensure quality under a production-like environment before application deployment.

How do I run Rails server in developer mode?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .


1 Answers

You can set the environment for each instance using the rails_env option. For example:

server {
  listen 443;
  server_name staging.myapp.com;
  root /apps/myapp/staging/public;
  passenger_enabled on;
  rails_env staging;
}
like image 81
htanata Avatar answered Oct 14 '22 03:10

htanata