Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Redmine + Ruby + Passenger + Nginx 專案管理平台部署實戰

編輯:Linux 系統常見問題解答

專案背景

Redmine 是功能強大的開源專案管理與缺陷追蹤工具,支援多專案、甘特圖、行事曆、Wiki、文件管理等。本文記錄在 Ubuntu 環境下,使用 RVM 管理 Ruby、Passenger 整合 Nginx 部署 Redmine 的完整流程,解決 Webrick 效能不足的生產環境部署問題。

第一步:安裝 Ruby + Rails 環境(推薦 RVM)

  • 參考官方指南:Ruby China 安裝指南
  • 關鍵提示:避免在 root 環境下安裝,建議使用普通用戶(如 zhangnq)透過 RVM 安裝,環境隔離更乾淨。
  • 安裝穩定版 Ruby(如 1.9.3-p545 或 2.x 系列)與 Bundler:
    rvm install 1.9.3-p545; gem install bundler

第二步:安裝 Redmine 核心程式

  • 參考官方 Wiki:RedmineInstall
  • 下載穩定版源碼,配置 config/database.yml(MySQL/PostgreSQL)、config/configuration.yml(郵件設定)。
  • 執行遷移與初始資料載入:
    bundle install --without development test
    rake generate_secret_token
    RAILS_ENV=production rake db:migrate
    RAILS_ENV=production rake redmine:load_default_data
  • 注意:內建 Webrick 僅適合測試,生產環境必須搭配 Passenger/Unicorn/Puma 等應用伺服器。

第三步:安裝 Passenger

gem install passenger
# 獲取 Passenger 根目錄(編譯 Nginx 模組需用)
passenger-config --root
# 輸出範例:/home/zhangnq/.rvm/gems/ruby-1.9.3-p545/gems/passenger-4.0.40

第四步:重新編譯 Nginx 整合 Passenger 模組

若已安裝 Nginx,建議重新編譯而非使用 passenger-install-nginx-module 全新安裝,以保留現有配置。

./configure \
  --user=www --group=www \
  --prefix=/usr/local/nginx \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --with-http_gzip_static_module \
  --with-ipv6 \
  --add-module=/home/zhangnq/.rvm/gems/ruby-1.9.3-p545/gems/passenger-4.0.40/ext/nginx/
make && make install

常見錯誤:若報 'ngx_http_connection_t' has no member named 'ssl',表示 Nginx 版本過舊(< 1.4),需升級至 1.4.7+ 後重試。

第五步:配置 Nginx 載入 Passenger 並代理 Redmine

編輯 /usr/local/nginx/conf/nginx.conf,在 http 區塊新增:

passenger_root /home/zhangnq/.rvm/gems/ruby-1.9.3-p545/gems/passenger-4.0.40;
passenger_ruby /home/zhangnq/.rvm/gems/ruby-1.9.3-p545/wrappers/ruby;

在 server 區塊配置 Redmine 站點:

server {
    listen 80;
    server_name redmine.example.com;
    root /var/www/redmine/public;  # 指向 Redmine public 目錄
    passenger_enabled on;
    rails_env production;
    # 靜態資源快取
    location ~ ^/(images|javascripts|stylesheets|fonts)/ {
        expires max;
        add_header Cache-Control public;
    }
}

關鍵點:passenger_root 必須正確指向 Passenger gem 目錄,許多教程漏掉此項導致 Nginx 啟動後無法載入應用。

總結與心得

  • RVM + Passenger + Nginx 是穩定、易維護的部署組合。
  • 配置過程中遇到錯誤(編譯失敗、權限、路徑)論善用 Google 與官方文檔排查。
  • 對新技術保持開放心態,逐步拆解問題,最終皆能攻克。
參考資源:Phusion Passenger Nginx 官方文檔
Copyright © Windows教程網 All Rights Reserved