在linux中|linux中ruby2.1+ redmine2.5+nginx 配置

更新时间:2019-08-19    来源:ruby    手机版     字体:

【www.bbyears.com--ruby】

在同一台服务器上装了redmine和gitlab 配置redmine + nginx的时候各种折腾

启动方法1:ruby script/rails server webrick -e production -d  默认的测试程序配置好了没的方法 人多了就不行了

启动方法2:ruby script/rails server mongrel -e production -d -p3000 稍微强点 不过人民大众还是说慢

逐研究NGINX方法

1:准备用mongrel + nginx的方法 没折腾成功放弃

安装nginx

我下载的版本是 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
有关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

测试是否部署成功

在浏览器输入server_name,(我这里用的是redmine.moon.ossxp.com),按回车键,如果显示redmine主页,则证明部署成功

出现的错误:em_plugin.rb:109:in `load": uninitialized constant Gem::SourceIndex (NameError)


2:用unicorn + nginx

参考:http://blog.davidanguita.name/2013/03/03/setting-up-a-cheap-redmine-server-using-unicorn-and-apache/ 或者类似和国内BLOG 启动的时候失败

命令: unicorn_rails -c shared/config/redmine/unicorn.rb -p 5000 -E production -D

出现的错误:runtime.rb:34:in `block in setup": You have already activated rack 1.5.2, but your Gemfile requires rack 1.4.5. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)

也是各种搜索 没解决,因为GITLAB和这个在同一台服务器  有几篇文章让卸载1.5.2的没敢动 搜索到下面这篇折腾了下成功了

参考:http://qiita.com/issobero/items/4ca5bb5f8508c25c8d45

使用命令:bundle exec unicorn_rails -E production -c config/unicorn.rb -D

不懂RUBY就仅仅记录了 方便遇到问题的同学参考。

ps 到了这里配置就介绍完了,文章有两个国外地址小编就整理过来,大家可以进入到地址去看看。

本文来源:http://www.bbyears.com/jiaocheng/63038.html