用于Debian 6中Ruby on Rails应用程序的Phusion Passenger + Nginx虚拟主机配置 [英] Phusion Passenger + Nginx Virtual Host Configuration for Ruby on Rails Application in Debian 6

查看:82
本文介绍了用于Debian 6中Ruby on Rails应用程序的Phusion Passenger + Nginx虚拟主机配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,在以下情况下,如何使用Debian 6下的Phusion Passenger + Nginx将端口80的所有实例映射到适当的相同子域.

注意:我是Ruby和Rails的新手,无法将我的观点表达为问题,如果我错了或纠正我,请原谅我.

Note : i am newbie to ruby on rails and server hosting , i unable to express my vision as question , please forgive me if i am wrong or correct me.

您好,我正在开发一种使用Rails on Rails开发的产品,它将托管在具有32 GB Ram和8 Core Server Processor的专用服务器中.每个客户端应具有单独的数据库和单独的rails实例.我正在复制-使用单独的文件夹为每个客户端复制代码,并提供不同的数据库名称,因此每个都充当不同的实例.基本上,所有客户端的源代码都是相同的,但是只有数据库名称不同,所以我将源代码放入不同的文件夹中,并为每个客户端盯着一个单独的rails应用程序.

Hi , i am having an one product developed using ruby on rails , going to host in an dedicated server with 32 GB Ram and 8 Core Server Processor. Each client should have seperate DB and separate rails instance. I am replicating - duplicating code for each client with separate folders and giving different database names and so each serving as an different instance. Basically Source code is same for all client but only database name differs, so i am putting source code into different folders and staring as an separate rails application for each client.

例如:

我有一个主临时域

www.product.com

对于每个客户端,我需要将单独的子域映射到具有相同端口的同一服务器(80) 但具有不同的Rails实例名称

For each client i need to have separate sub domain mapped to same server with same port(80) but with different rails instance name

www.client1.product.com
www.client2.product.com
www.clientn.product.com

据我所知,如果我启动rails实例,每个实例将从单独的端口号

As i know if i start rails instance , each will start at seperate port no's

client1 with start at port 3001
client2 with start at port 3002
client3 with start at port 3003

我的问题是如何使用Debian 6下的Phusion Passenger + Nginx将端口80的所有实例映射到适当的相同子域

如果我访问

www.client4.product.com,我需要使应用程序在端口3004上运行

www.client4.product.com , i need to get app running in port 3004

推荐答案

我希望您现在已经找到解决方案,但是为了stackoverflow存档,我将提供一个答案.

I hope you found the solution by now, but for the sake of stackoverflow archive I'm going to provide an answer.

一般来说,您应该使用反向代理( http://wiki.nginx.org/RubyonRailsMongrel )使用nginx时,您的上游将是运行专用rails应用程序的乘客|瘦|独角兽|美洲狮|杂种(选择您喜欢的服务器)(我将使用重复的代码来隔离您的客户端运行环境.)用这种方法提供负载平衡.

Generaly meaning you should use reverse proxy (http://wiki.nginx.org/RubyonRailsMongrel) with nginx, while your upstream will be a passenger|thin|unicorn|puma|mongrel (pick your favorite) server runnning your dedicated rails application (I will use duplicated code in order to isolate your client running environment.) You'll be able to provide load balancing with this method.

现在,您规定了使用passenger的方式,如果您使用具有乘客扩展性的nginx进行编译,则可以使用一个非常简单的设置. (转到 http://www.modrails.com/documentation/Users%20guide% 20Nginx.html 以获得更好的解释)

Now, you stipulate the use of Passenger, you could use a really simple setup if you compile nginx with passenger extention. (go to http://www.modrails.com/documentation/Users%20guide%20Nginx.html for better explanation)

server {
  listen 80;
  listen [::]:80 default_server ipv6only=on; # please for a better world be IPv6 compliant !
      server_name www.client1.product.com;
  root /my/rails/app1;
      passenger_enabled on;
}
server {
  listen 80;
  listen [::]:80 default_server ipv6only=on;
      server_name www.client2.product.com;
  root /my/rails/app2;
      passenger_enabled on;
}

.......

这篇关于用于Debian 6中Ruby on Rails应用程序的Phusion Passenger + Nginx虚拟主机配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆