Nginx+mongrel部署Rails应用
安装nginx
下载地址 http://nginx.org/en/download.html
我下载的版本是 nginx-0.8.40.tar.gz
解压安装
tar -zxvf nginx-0.8.40.tar.gz cd nginx-0.8.40/ .configure make sudo make install
默认情况下安装目录是 /usr/local/nginx
安装mongrel和mongrel_cluster
sudo gem install mongrel mongrel_cluster
由于用gem安装后mongrel_rails命令被放在 /var/lib/gems/1.8/bin/mongrel_rails,使用不方便,所以建议建立符号链接
sudo ln -s /var/lib/gems/1.8/bin/mongrel_rails /usr/bin/mongrel_rails
部署Rails应用
我的应用示例是redmine,一个用Rails做的项目管理工具。redmine安装路径是 /opt/redmine
配置nginx,添加一个server块,用于服务redmine
编辑 vi /usr/local/nginx/conf/nginx.conf,以下是添加的内容
upstream mongrel { server 127.0.0.1:8000; server 127.0.0.1:8001; } # rails server server { listen 80; server_name redmine.moon.ossxp.com; root /opt/redmine/public; #注意这里一定要指向Rails应用的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; } }
配置mongrel_cluster
在Rails项目的根目录下执行以下命令,生成config/mongrel_cluster.yml 文件,供启用mongrel集群使用
sudo mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N 2 -c+工程目录
有关cluster::configure 更多参数使用可借助帮助命令查看
mongrel_rails cluster::configure -h
生成的文件内容如下:
--- address: 127.0.0.1 log_file: log/mongrel.log port: "8000" environment: production pid_file: tmp/pids/mongrel.pid servers: 2
启用mongrel_cluster
wangsheng@pc01:/opt/redmine$ sudo mongrel_rails cluster::start starting port 8000 starting port 8001
启用nginx
sudo /usr/local/nginx/sbin/nginx
或者:[root@localhost ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
测试是否部署成功
在浏览器输入server_name,(我这里用的是redmine.moon.ossxp.com),按回车键,如果显示redmine主页,则证明部署成功。
相关推荐
JOO 2020-04-26
踩风火轮的乌龟 2008-03-22
wangyongwyk 2011-07-31
wl00 2020-10-28
EricNet 2020-07-05
EricNet 2020-05-27
何志文 2020-05-11
happyfreeangel 2020-04-09
Poisedflw 2020-03-23
yangliuhbhd 2020-03-06
Ben的程序员生涯 2013-06-01
chenshuixian 2013-06-01
wes0 2014-05-31
mrice00 2019-12-20
EricNet 2019-12-11
89304896 2019-12-08
lihaoningxia 2013-07-09