しゅがーブログ

技術ネタとか書いていけたらな…

Rails3 + Passenger について

今更ながらRails3 + Passenger + Apacheの環境について調べました。
Railsは3.0.1のためassets pipelineがありません。
そのため、publicディレクトリに置いてあるJavaScriptCSSApacheモジュールのPassengerが圧縮しているみたいです。

Passenger

環境

  • production
  • staging
  • development

基本的に環境はhttpd.confに依存しています。
デフォルトではproductionで動作するようになっているため、production以外の環境はそれぞれ下記のような環境変数を指定してあげるとよさそうです。

httpd.conf

<Directory "/var/www/html">
    Order allow,deny
    Allow from all
    RailsEnv development #ここ
</Directory>

圧縮をかけるコンテンツフィルターはこんな感じで指定できます。

httpd.conf

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

FilterDeclare Compression CONTENT_SET
FilterProvider Compression DEFLATE Content-Type $text/plain
FilterProvider Compression DEFLATE Content-Type $text/css
FilterProvider Compression DEFLATE Content-Type $application/xhtml
FilterProvider Compression DEFLATE Content-Type $application/xml
FilterProvider Compression DEFLATE Content-Type $application/xhtml+xml
FilterProvider Compression DEFLATE Content-Type $application/rss+xml
FilterProvider Compression DEFLATE Content-Type $application/atom+xml
FilterProvider Compression DEFLATE Content-Type $application/x-javascript
FilterProvider Compression DEFLATE Content-Type $image/svg+xml
FilterProvider Compression DEFLATE Content-Type $text/html
FilterProvider Compression DEFLATE Content-Type $application/javascript
FilterChain Compression

あまりにもローカル環境が遅いためPassengerを利用して開発してみようと思い調べてみました。
ローカル環境でシンプルに開発するならやっぱりでWEBrickがいいのかな。
もしくはDockerで各種コンテナを用意して、開発した方が楽そうだな・・

参考

Rails3 事始め: Passenger で development モードで動かす
【Apache】サイトのコンテンツ全てをgzip圧縮する | blog.remora.cx
Apache 2.2 mod_filterを使いこなす – AddOutputFilterByType DEFLATE text/htmlを書き換えてみる – cyano