<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>船長日誌 &#187; rails</title>
	<atom:link href="http://www.cslog.cn/tag/rails/feed/zh-hant/" rel="self" type="application/rss+xml" />
	<link>http://www.cslog.cn</link>
	<description>最讓我激動的是不知道下一個星球上能發現什麼...</description>
	<lastBuildDate>Wed, 30 Jul 2025 16:06:05 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>太噁心了&#8211; rubygems安裝gem需要使用代理服務器了</title>
		<link>http://www.cslog.cn/Content/g-f-w-ni-ma-de/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/g-f-w-ni-ma-de/zh-hant/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 07:43:14 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[privoxy]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubygems]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=887</guid>
		<description><![CDATA[換了一台電腦，想用rubygems重新安裝rails，但一直遇到各種如問題： s &#8230; <a href="http://www.cslog.cn/Content/g-f-w-ni-ma-de/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>換了一台電腦，想用rubygems重新安裝rails，但一直遇到各種如問題：</p>
<pre>sudo gem install -v=2.3.9 rails
Password:
ERROR:  Could not find a valid gem 'rails' (= 2.3.9) in any repository
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    too many connection resets (http://production.s3.rubygems.org/latest_specs.4.8.gz)</pre>
<p>或</p>
<pre>ERROR: While executing gem ... (Gem::DependencyError)
  Unable to resolve dependencies: rails requires activesupport (= 3.0.5), actionpack (= 3.0.5), activerecord (= 3.0.5), activeresource (= 3.0.5), actionmailer (= 3.0.5), railties (= 3.0.5), bundler (~&gt; 1.0)</pre>
<p>google了半天（期間google中短NNN次），才明天了現在<a href="http://hi.baidu.com/sitoto/blog/item/d00fd658fa6f469c810a181e.html">使用rubygems 安裝gem也得開代理了</a>。。。</p>
<p>要使用加了代理的命令：</p>
<pre>sudo gem install rails -p http://127.0.0.1:8118</pre>
<p>現在rubygems好像只支持http代理。 如果你使用的是socks代理，可以通過Privoxy（支持linux和mac)這個軟件來搞一個http代理 通道， 詳細參看<a href="http://www.cnblogs.com/another-wheel/archive/2011/11/16/setup-http-proxy-via-socks-and-privoxy.html">這個教程</a>。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/g-f-w-ni-ma-de/zh-hant/">http://www.cslog.cn/Content/g-f-w-ni-ma-de/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/g-f-w-ni-ma-de/feed/zh-hant/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>使用Unicorn替代Mongrel作為Ruby on Rails的服務器</title>
		<link>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 16:54:41 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[unicorn]]></category>
		<category><![CDATA[服務器]]></category>
		<category><![CDATA[網站開發]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=727</guid>
		<description><![CDATA[先前的開發的Ruby on Rails網站使用的服務程序是Mongrel + N &#8230; <a href="http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>先前的開發的Ruby on Rails網站使用的服務程序是<a title="在ubuntu6.06上安裝apache2.2X + mysql + PHP + Ruby on Rails + Mongrel Cluster | 船長日誌" href="http://www.cslog.cn/Content/ubuntu606_mysql_apache2_ruby_rails_mongrel_cluster/">Mongrel + Nginx</a>， 現在用了Rails 3， 發現Mongrel對它有兼容問題， 所以要換一個。 雖然現在<a title="Overview — Phusion Passenger™ (a.k.a. mod_rails / mod_rack)" href="http://www.modrails.com/">Phusion Passenger</a>大行其道， 但使用前要重新編譯Nginx。 為了避免重新安裝nginx，我找到mongrel的替代品<a title="File: README [Unicorn: Rack HTTP server for fast clients and Unix]" href="http://unicorn.bogomips.org/">Unicorn</a>。 沒想到unicorn的設置非常方便。 我記錄在這裡供大家參考：</p>
<p>安裝unicorn:<br />
<code><br />
sudo gem install unicorn<br />
</code></p>
<p>創建網站配置文件(myproject是項目名稱):<br />
<code><span id="more-727"></span><br />
sudo mkdir /etc/unicorn<br />
cd /etc/unicorn/<br />
sudo nano /etc/unicorn/myproject.conf<br />
</code></p>
<p>內容如下：<br />
<code><br />
RAILS_ROOT=/www/myproject<br />
RAILS_ENV=production<br />
</code></p>
<p>在網站里再創建一個unicorn配置文件<br />
<code><br />
nano /www/myproject/config/unicorn.rb<br />
</code></p>
<p>內容如下：<br />
<code><br />
# Minimal sample configuration file for Unicorn (not Rack) when used<br />
# with daemonization (unicorn -D) started in your working directory.<br />
#<br />
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete<br />
# documentation.<br />
# See also http://unicorn.bogomips.org/examples/unicorn.conf.rb for<br />
# a more verbose configuration using more features.</code></p>
<p><code> </code></p>
<p><code>app_path = "/www/myproject"</code></p>
<p><code> </code></p>
<p><code>listen 8080 # by default Unicorn listens on port 8080<br />
worker_processes 2 # this should be &gt;= nr_cpus<br />
pid "#{app_path}/tmp/pids/unicorn.pid"<br />
stderr_path "#{app_path}/log/unicorn.log"<br />
stdout_path "#{app_path}/log/unicorn.log"<br />
</code></p>
<p>設置unicorn啟動腳本：<br />
<code><br />
sudo nano /etc/init.d/unicorn_init<br />
</code><br />
腳本內容：<br />
<code><br />
#!/bin/sh<br />
#<br />
# init.d script for single or multiple unicorn installations. Expects at least one .conf<br />
# file in /etc/unicorn<br />
#<br />
# Modified by jay@gooby.org http://github.com/jaygooby<br />
# based on http://gist.github.com/308216 by http://github.com/mguterl<br />
#<br />
## A sample /etc/unicorn/my_app.conf<br />
##<br />
## RAILS_ENV=production<br />
## RAILS_ROOT=/var/apps/www/my_app/current<br />
#<br />
# This configures a unicorn master for your app at /var/apps/www/my_app/current running in<br />
# production mode. It will read config/unicorn.rb for further set up.<br />
#<br />
# You should ensure different ports or sockets are set in each config/unicorn.rb if<br />
# you are running more than one master concurrently.<br />
#<br />
# If you call this script without any config parameters, it will attempt to run the<br />
# init command for all your unicorn configurations listed in /etc/unicorn/*.conf<br />
#<br />
# /etc/init.d/unicorn start # starts all unicorns<br />
#<br />
# If you specify a particular config, it will only operate on that one<br />
#<br />
# /etc/init.d/unicorn start /etc/unicorn/my_app.conf</code></p>
<p><code> </code></p>
<p><code>set -e</code></p>
<p><code>sig () {<br />
test -s "$PID" &amp;&amp; kill -$1 `cat "$PID"`<br />
}</p>
<p>oldsig () {<br />
test -s "$OLD_PID" &amp;&amp; kill -$1 `cat "$OLD_PID"`<br />
}</p>
<p>cmd () {</p>
<p>case $1 in<br />
start)<br />
sig 0 &amp;&amp; echo &gt;&amp;2 "Already running" &amp;&amp; exit 0<br />
echo "Starting"<br />
$CMD<br />
;;<br />
stop)<br />
sig QUIT &amp;&amp; echo "Stopping" &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Not running"<br />
;;<br />
force-stop)<br />
sig TERM &amp;&amp; echo "Forcing a stop" &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Not running"<br />
;;<br />
restart|reload)<br />
sig USR2 &amp;&amp; sleep 5 &amp;&amp; oldsig QUIT &amp;&amp; echo "Killing old master" `cat $OLD_PID` &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't reload, starting '$CMD' instead"<br />
$CMD<br />
;;<br />
upgrade)<br />
sig USR2 &amp;&amp; echo Upgraded &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't upgrade, starting '$CMD' instead"<br />
$CMD<br />
;;<br />
rotate)<br />
sig USR1 &amp;&amp; echo rotated logs OK &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't rotate logs" &amp;&amp; exit 1<br />
;;<br />
*)<br />
echo &gt;&amp;2 "Usage: $0 "<br />
exit 1<br />
;;<br />
esac<br />
}</p>
<p>setup () {</p>
<p>echo -n "$RAILS_ROOT: "<br />
cd $RAILS_ROOT || exit 1<br />
export PID=$RAILS_ROOT/tmp/pids/unicorn.pid<br />
export OLD_PID="$PID.oldbin"</p>
<p>CMD="/usr/bin/unicorn_rails -c config/unicorn.rb -E $RAILS_ENV -D"<br />
}</p>
<p>start_stop () {</p>
<p># either run the start/stop/reload/etc command for every config under /etc/unicorn<br />
# or just do it for a specific one</p>
<p># $1 contains the start/stop/etc command<br />
# $2 if it exists, should be the specific config we want to act on<br />
if [ $2 ]; then<br />
. $2<br />
setup<br />
cmd $1<br />
else<br />
for CONFIG in /etc/unicorn/*.conf; do<br />
# import the variables<br />
. $CONFIG<br />
setup</p>
<p># run the start/stop/etc command<br />
cmd $1<br />
done<br />
fi<br />
}</p>
<p></code></p>
<p><code>ARGS="$1 $2"<br />
start_stop $ARGS<br />
</code><br />
注意將裡面的/usr/bin/unicorn_rails 換成你系統中unicorn_rails程序的實際路徑。</p>
<p>設置unicorn_init文件屬性:<br />
<code><br />
sudo chmod 755 /etc/init.d/unicorn_init<br />
</code></p>
<p>啟動unicorn:<br />
<code><br />
/etc/init.d/unicorn_init<br />
</code></p>
<p>修改nginx的配置文件，加入unicorn的代理設置：<br />
<code><br />
upstream myproject_mongrel {<br />
server 127.0.0.1:8080 fail_timeout=0;<br />
}<br />
</code><br />
這部分跟使用mongrel的類似的。</p>
<p>這樣unicorn的設置就完成了。 剛設置好，感覺unicorn跟mongrel一樣， 都是比較吃內存的， 一啟動就佔了50M. 不知道會不會也像mongrel一樣把內存吃爆， 會得話得設置監控軟件（如god）看住它。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/">http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/feed/zh-hant/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- WP Chinese Conversion Full Page Converted -->