Nginx和Redmine

csfreebird發表於2013-07-24

緊接前文,我希望能夠用FastCGI協議和Nginx互動,這樣就能用在產品環境下。

Redmine啟用FastCGI文件不全,靠自己揣摩和Google得到的零散資訊,得到如下配置方法:

1. 安裝需要的開發庫

apt-get install libfcgi-dev

2. 在redmine目錄下建立檔案Gemfile.local, 內容如下:

gem "fcgi"

3. 安裝依賴,再次執行下面的命令:

bundle install --without development test

4. 強制環境變數為production,在config/environment.rb中第一行新增:

ENV['RAILS_ENV'] ||= 'production'

5. 安裝啟動fastcgi的工具軟體

apt-get install spawn-fcgi

6. 啟動:

cp public/dispatch.fcgi.example public/dispatch.fcgi
spawn-fcgi -p 9001 -f ./public/dispatch.fcgi


現在檢查一下是否監聽了9001埠:

root@redmine:~/redmine-2.3# fuser -n tcp 9001
9001/tcp:            26510
root@redmine:~/redmine-2.3# ps -def | grep dispatch
root     26510     1  2 12:53 ?        00:00:04 ruby ./public/dispatch.fcgi

7. 現在假定已經安裝了Nginx,在conf.d/default.conf檔案中新增幾行配置:

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9001                                                                                                         
    location / {                                                                                                                    
	fastcgi_pass   127.0.0.1:9001; 
	fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
	include        fastcgi_params;
    }

8. 開啟網頁測試,通過!!!

如果想支援HTTPS,可以像下面這樣在Nginx的conf.d目錄下建立一個redmin.conf檔案

server {
    listen       443;
    server_name  your_domain_name
    ssl                  on;
    ssl_certificate ./conf.d/server.crt;
    ssl_certificate_key ./conf.d/server.key;

    location = /favicon.ico {
        log_not_found off;
        log_subrequest off;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9001                                                                                                         
    location / {
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }
}

注意,還有另一種方式,通過passenger,請參考別人的文章。 因為經過實際運用,我的方式有時候redmine 會crash, 而且我還沒有找到原因,因為我對ruby on rails不熟悉。

http://www.cnblogs.com/csharpsharper/p/3250913.html

https://forums.freebsd.org/viewtopic.php?&t=41256

相關文章