Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2548137
  • 博文数量: 2110
  • 博客积分: 18861
  • 博客等级: 上将
  • 技术积分: 24420
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-05 18:23
文章分类

全部博文(2110)

文章存档

2011年(139)

2010年(1971)

我的朋友

分类: LINUX

2011-02-06 23:45:13

简单的安装和试用了一下 Redmine,发现 Redmine 的界面很简单清新、使用也很方便,需要的功能都有。今天打算部署到稍微专业一点的环境,Ruby on Rails 的部署方案主要有以下几种:

  • Lighttpd + FastCGI
  • Nginx + Mongrel
  • Nginx + Thin
  • Nginx + Phusion Passenger
  • Apache2 + Thin
  • Apache2 + Phusion Passenger (Mod_Rails)

目前用的比较多、比较成熟的要算 Nginx + Mongrel 和 Apache2 + Passenger 了,Apache2 + Passenger 配置很简单,非常适合多 ruby app 的部署。考虑到成熟、稳定、而且 VPSee 对 Nginx 比较熟悉,所以选定 Nginx + Mongrel 组合作为 Redmine 环境的部署方案。以下的内容虽然以 Redmine 为例来描述如何部署 Nginx + Mongrel,其配置方法也适用与一般 Rails 程序部署的情况。

安装和配置 Ruby on Rails

详细参考 “CentOS 5 上配置 Redmine 和 Git” 中的 “安装必要的软件包” 和 “安装和配置 Ruby on Rails”.

安装和配置 Mongrel

拷贝 mongrel_cluster 启动文件到 /etc/init.d/,在 /etc 下创建一个目录 mongrel_cluster 用来存放 mongrel 程序的配置文件,配置文件必须以 yml 扩展名结尾,不能是 yaml,最后修改 yml 配置文件,注意 user/group 要和的对上,否则 mongrel_cluster 启动不了:

# gem install mongrel
# gem install mongrel_cluster

# cp /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources \
/mongrel_cluster /etc/init.d/
# chmod +x /etc/init.d/mongrel_cluster
# /sbin/chkconfig --level 345 mongrel_cluster on

# mkdir /etc/mongrel_cluster
cp /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/defaults.yaml /etc/mongrel_cluster/redmine.yml

# vi /etc/mongrel_cluster/redmine.yml
---
cwd: /home/redmine/
port: "9000"
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 4
group: redmine
user: redmine

启动 mongrel:

# /etc/init.d/mongrel_cluster start

安装配置 Nginx

安装完 nginx 后需要修改配置文件,nginx 支持模块化配置,为了更清晰最好把全局配置文件和 virtal host 配置文件分开,先是修改 nginx 的全局配置文件:

# yum install nginx

# vi /etc/nginx/nginx.conf
user              nginx;
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;

    log_format  main  '$remote_addr - $remote_user [$time_local] $request'
                      '"$status" $body_bytes_sent "$http_referer"'
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     off;
    keepalive_timeout  65;

    gzip  on;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_types text/plain text/html text/css application/x-javascript
text/xml application/xml application/xml+rss text/javascript;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/vhosts/*;
}

接着在 /etc/nginx/ 下面创建一个文件夹 vhosts 用来存放多个 virtual host 局部配置文件:

# mkdir /etc/nginx/vhosts
# vi /etc/nginx/vhosts/vpsee.com.conf

upstream mongrel_server {
        server 127.0.0.1:9000;
        server 127.0.0.1:9001;
        server 127.0.0.1:9002;
        server 127.0.0.1:9003;
}

server {
        listen  80;
        server_name  vpsee.com 

        client_max_body_size 10M;
        root   /home/redmine;

        access_log  /var/www/access_vpsee.com.log  main;

        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect false;
            proxy_max_temp_file_size 0;

            if (-f $request_filename) {
                break;
            }
            if (-f $request_filename/index.html) {
                rewrite (.*) $1/index.html break;
            }
            if (-f $request_filename.html) {
                rewrite (.*) $1.html break;
            }
            if (!-f $request_filename) {
                proxy_pass 
                break;
            }
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
}

启动 nginx:

# /etc/init.d/nginx start

打开浏览器应该就可以访问了。

阅读(465) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~