2007-07-27
使用了nginx+mongerl来搭建了rails的生产环境
最近网上有很多人在推荐使用nginx+mongerl来搭建了rails的生产环境,今天研究了一下。
在ubuntu上安装nginx比较简单 sudo apt-get install nginx 就可以了,如果要安装最新的版本可以去nginx的官方网站上去下载。
ubuntu上搭建rails的已经存在ubuntu的源库中,只要使用apt-get install rails 但是安装的不是最新的的版本。在gem install 分别安装 mongel 和Mongrel_cluster。
假如你的rails工程放在/var/www/myapp/下
以上命令多是root用户
访问一下http://localhost:3000 看一下你的mongrel是否能启动 能启动,则继续搭建mongerl的集群,
这样会在test工程下生成一个config/mongrel_cluster.yml 这样一个配置文件。记录了相关的配置信息。
你也可以把mongrel_rails 作为系统服务
你就可以在/etc/init.d/mongrel_cluster start 来启动这个mongrel的集群
接下来配置nginx 他的配置文件比较简单/etc/nginx/nginx.conf
下面可以帖一个简单的配置文件
在ubuntu上安装nginx比较简单 sudo apt-get install nginx 就可以了,如果要安装最新的版本可以去nginx的官方网站上去下载。
ubuntu上搭建rails的已经存在ubuntu的源库中,只要使用apt-get install rails 但是安装的不是最新的的版本。在gem install 分别安装 mongel 和Mongrel_cluster。
假如你的rails工程放在/var/www/myapp/下
adduser mongrel
cd /var/www/myapp
rails test
cd test
mongrel_rails start
chown -R mongrel:mongrel /var/www/myapp/test
以上命令多是root用户
访问一下http://localhost:3000 看一下你的mongrel是否能启动 能启动,则继续搭建mongerl的集群,
sudo mongrel_rails cluster::configure -e production \-p 8000 -N 3 -c /var/www/myapp/test -a 127.0.0.1 \ --user mongrel --group mongrel
这样会在test工程下生成一个config/mongrel_cluster.yml 这样一个配置文件。记录了相关的配置信息。
mongrel_rails cluster::start就可以把起来了三个mongrel进程。
你也可以把mongrel_rails 作为系统服务
$ sudo mkdir /etc/mongrel_cluster
$ sudo cp /var/www/myapp/test/config/mongrel_cluster.yml \
/etc/mongrel_cluster/testapp.yml
$ sudo cp \
/path/to/mongrel_cluster_gem/resources/mongrel_cluster/mongrel_rails \
/etc/init.d/
$ sudo chmod +x /etc/init.d/mongrel_cluster
你就可以在/etc/init.d/mongrel_cluster start 来启动这个mongrel的集群
接下来配置nginx 他的配置文件比较简单/etc/nginx/nginx.conf
下面可以帖一个简单的配置文件
user mongrel;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
upstream mongrel {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
}
gzip on;
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location / {
root /var/www/myapp/test/public;
index index.html index.htm;
}
location / {
proxy_pass http://mongrel;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {
root /var/www/myapp/test/public;
}
}
} 在nginx重启一下 访问一下http://localhost 一个简单的rails的生产环境就搭建完成了
评论
ashchan
2008-01-02
miaoxingfu 写道
ashchan 写道
miaoxingfu 写道
受教了!不过还要请教个问题:如何在nginx+mongrel中配置两台虚拟主机呢?两个域名,但是同时使用80端口?遇到在同一台服务器上提供两个不同的web服务,有两个域名指向了同一台服务器的问题,恳请赐教。大谢!
设置虚拟主机,只要在http设置节点下增加server节点即可,例:
http {
...
server {
listen 80;
server_name domain1.com;
location / {
root /home/someguy/domain1/;
index index.html index.htm;
}
....
}
server {
listen 80;
server_name domain2.com;
location / {
root /home/someguy/domain2/;
index index.html index.htm;
}
....
}
}
当然如果要布署的是多个rails应用,则相应server设置要设好。
我测试了一下,光增加server节点是不够的,还需要增加upstream节点才行。
呵呵,因为虚拟主机不仅限于rails应用;而upstream是用于负载均衡的:)
miaoxingfu
2008-01-02
ashchan 写道
miaoxingfu 写道
受教了!不过还要请教个问题:如何在nginx+mongrel中配置两台虚拟主机呢?两个域名,但是同时使用80端口?遇到在同一台服务器上提供两个不同的web服务,有两个域名指向了同一台服务器的问题,恳请赐教。大谢!
设置虚拟主机,只要在http设置节点下增加server节点即可,例:
http {
...
server {
listen 80;
server_name domain1.com;
location / {
root /home/someguy/domain1/;
index index.html index.htm;
}
....
}
server {
listen 80;
server_name domain2.com;
location / {
root /home/someguy/domain2/;
index index.html index.htm;
}
....
}
}
当然如果要布署的是多个rails应用,则相应server设置要设好。
我测试了一下,光增加server节点是不够的,还需要增加upstream节点才行。
ashchan
2007-12-30
miaoxingfu 写道
受教了!不过还要请教个问题:如何在nginx+mongrel中配置两台虚拟主机呢?两个域名,但是同时使用80端口?遇到在同一台服务器上提供两个不同的web服务,有两个域名指向了同一台服务器的问题,恳请赐教。大谢!
设置虚拟主机,只要在http设置节点下增加server节点即可,例:
http {
...
server {
listen 80;
server_name domain1.com;
location / {
root /home/someguy/domain1/;
index index.html index.htm;
}
....
}
server {
listen 80;
server_name domain2.com;
location / {
root /home/someguy/domain2/;
index index.html index.htm;
}
....
}
}
当然如果要布署的是多个rails应用,则相应server设置要设好。
yangzx554
2007-12-29
t0uch 写道
用ubuntu get下来的做生产环境,怎么感觉很怪
这个只是玩票性质,当然真实环境最好有编译源代码
t0uch
2007-12-29
用ubuntu get下来的做生产环境,怎么感觉很怪
miaoxingfu
2007-12-28
受教了!不过还要请教个问题:如何在nginx+mongrel中配置两台虚拟主机呢?两个域名,但是同时使用80端口?遇到在同一台服务器上提供两个不同的web服务,有两个域名指向了同一台服务器的问题,恳请赐教。大谢!
yangzx554
2007-09-10
suave 写道
ubuntu feisty带的nginx在remove的时候会出问题。
楼主讲下在启用rails cache以后配置文件应该如何写,比如把所有的cache文件都存在public/cache下面。好像要加很多location吧?
remove的时候没有测试过,用cache觉得尽量应该用memcache,楼主讲下在启用rails cache以后配置文件应该如何写,比如把所有的cache文件都存在public/cache下面。好像要加很多location吧?
suave
2007-09-09
ubuntu feisty带的nginx在remove的时候会出问题。
楼主讲下在启用rails cache以后配置文件应该如何写,比如把所有的cache文件都存在public/cache下面。好像要加很多location吧?
楼主讲下在启用rails cache以后配置文件应该如何写,比如把所有的cache文件都存在public/cache下面。好像要加很多location吧?
lgn21st
2007-08-29
自己回答吧,我已经测试过,ubuntu7.04自带的nginx包不支持ssl,等到7.10就支持了。
lgn21st
2007-08-12
楼主是否有研究过如何让nginx开启ssl,可以用https协议访问,如果是ubuntu自带的nginx应该如何设置呢?
yangzx554
2007-08-09
probert 写道
failed (111: Connection refused) while reading response header from upstream, client: 192.168.1.10, server: localhost, URL: "/", upstream: "http://127.0.0.1:8000/", host: "192.168.1.110"
今天测试一下,如果你的mongerl的集群没有起来,会把这个错误的 ,你可以直接访问一下你的mongrel端口看看能不能访问
probert
2007-08-09
谢谢你的回答!单独的Mongrel是可以起来的,我再继续尝试吧。
yangzx554
2007-08-09
ruby和rails装的有点问题 是不是单独的Mongrel也起不来 ,我装的环境是ubuntu7.04,ruby是1.8.6 rails是1.2.3。ruby是用源码装的。
probert
2007-08-09
不是的,Ubuntu的IP是192.168.1.110,server_name设置为localhost,我也试过把server_name设置为IP地址一样的,效果还是不行。
注:我用192.168.1.10的机器来访问,不好意思,有点混淆了。
注:我用192.168.1.10的机器来访问,不好意思,有点混淆了。
yangzx554
2007-08-09
probert 写道
请教个问题,我在Ubuntu系统上配置好了Ruby On Rails环境,Ruby是最新的1.8.6版本,然后按照你的文章配置好后启动Mongrel集群,出现了以下错误:
** Ruby version is up-to-date; cgi_multipart_eof_fix was not loaded
访问站点只会出现“The page you are looking for is temporarily unavailable.
Please try again later.”这样的提示,在/var/log/nginx/error.log文件里的日志信息是:
failed (111: Connection refused) while reading response header from upstream, client: 192.168.1.10, server: localhost, URL: "/", upstream: "http://127.0.0.1:8000/", host: "192.168.1.110"
网上搜索了一圈只有一个回答:Ruby版本要安装到最新的1.8.6,可是我已经做了,请问有遇到过这种问题吗?谢谢
我这里是用localhost访问的,你是不是用192.168.1.110访问的 在nignx中的server_name 是不是要改一下啊** Ruby version is up-to-date; cgi_multipart_eof_fix was not loaded
访问站点只会出现“The page you are looking for is temporarily unavailable.
Please try again later.”这样的提示,在/var/log/nginx/error.log文件里的日志信息是:
failed (111: Connection refused) while reading response header from upstream, client: 192.168.1.10, server: localhost, URL: "/", upstream: "http://127.0.0.1:8000/", host: "192.168.1.110"
网上搜索了一圈只有一个回答:Ruby版本要安装到最新的1.8.6,可是我已经做了,请问有遇到过这种问题吗?谢谢
probert
2007-08-09
请教个问题,我在Ubuntu系统上配置好了Ruby On Rails环境,Ruby是最新的1.8.6版本,然后按照你的文章配置好后启动Mongrel集群,出现了以下错误:
** Ruby version is up-to-date; cgi_multipart_eof_fix was not loaded
访问站点只会出现“The page you are looking for is temporarily unavailable.
Please try again later.”这样的提示,在/var/log/nginx/error.log文件里的日志信息是:
failed (111: Connection refused) while reading response header from upstream, client: 192.168.1.10, server: localhost, URL: "/", upstream: "http://127.0.0.1:8000/", host: "192.168.1.110"
网上搜索了一圈只有一个回答:Ruby版本要安装到最新的1.8.6,可是我已经做了,请问有遇到过这种问题吗?谢谢
** Ruby version is up-to-date; cgi_multipart_eof_fix was not loaded
访问站点只会出现“The page you are looking for is temporarily unavailable.
Please try again later.”这样的提示,在/var/log/nginx/error.log文件里的日志信息是:
failed (111: Connection refused) while reading response header from upstream, client: 192.168.1.10, server: localhost, URL: "/", upstream: "http://127.0.0.1:8000/", host: "192.168.1.110"
网上搜索了一圈只有一个回答:Ruby版本要安装到最新的1.8.6,可是我已经做了,请问有遇到过这种问题吗?谢谢
- 浏览: 7019 次
- 性别:

- 来自: 杭州

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
使用了nginx+mongerl来 ...
miaoxingfu 写道ashchan 写道miaoxingfu 写道受教了! ...
-- by ashchan -
使用了nginx+mongerl来 ...
ashchan 写道miaoxingfu 写道受教了!不过还要请教个问题:如何在 ...
-- by miaoxingfu -
使用了nginx+mongerl来 ...
miaoxingfu 写道受教了!不过还要请教个问题:如何在nginx+mong ...
-- by ashchan -
使用了nginx+mongerl来 ...
t0uch 写道用ubuntu get下来的做生产环境,怎么感觉很怪这个只是玩票 ...
-- by yangzx554 -
使用了nginx+mongerl来 ...
用ubuntu get下来的做生产环境,怎么感觉很怪
-- by t0uch






评论排行榜