下面我們來看一篇小編總結的linux中ruby2.1+ redmine2.5+nginx 配置,如果有需要了解的朋友不防進入參考,配置過程復雜但文章思路淺析了.
在同一臺服務器上裝了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;
- } //Vevb.com
- }
配置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 到了這里配置就介紹完了,文章有兩個國外地址小編就整理過來,大家可以進入到地址去看看.
|
新聞熱點
疑難解答