Changes between Version 3 and Version 4 of TracFastCgi


Ignore:
Timestamp:
Jan 28, 2010, 4:25:36 AM (14 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracFastCgi

    v3 v4  
    1 = Trac を FastCGI で使用する =
    2 
    3 バージョン 0.9 以降、 Trac は [http://www.fastcgi.com/ FastCGI] インタフェースに対応するようになりました。 [wiki:TracModPython mod_python] 同様、 Trac を常駐させるため、外部の各リクエストに対して新しいプロセスを生成する CGI インタフェースよりも処理速度が速いです。その上 `mod_python` とは異なり [http://httpd.apache.org/docs/suexec.html SuEXEC] に対応することも可能です。また、より多くの種類の Web サーバにサポートされています。
    4 
    5 == 単純な Apache の設定 ==
    6 
    7 Apache で利用可能な FastCGI モジュールは 2 種類あります: `mod_fastcgi` と
    8 `mod_fcgid` です。 これ以降に書かれている `FastCgiIpcDir` と `FastCgiConfig` ディレクティブ
    9 は `mod_fastcgi` のディレクティブです; `DefaultInitEnv` は `mod_fgcid`
    10 のディレクティブです。
    11 
    12 `mod_fastcgi` では、 Apache の設定ファイルに以下の設定を追記します。
    13 ファイル:
     1= Trac with FastCGI =
     2
     3Since version 0.9, Trac supports being run through the [http://www.fastcgi.com/ FastCGI] interface. Like [wiki:TracModPython mod_python], this allows Trac to remain resident, and is faster than external CGI interfaces which must start a new process for each request. However, unlike mod_python, it is able to support [http://httpd.apache.org/docs/suexec.html SuEXEC]. Additionally, it is supported by much wider variety of web servers.
     4
     5{{{
     6#!html
     7<p style="background: #fdc; border: 2px solid #d00; font-style: italic; padding: 0 .5em; margin: 1em 0;">
     8<strong>Note for Windows:</strong> Trac's FCGI does not run under Windows, as Windows does not implement Socket.fromfd, which is used by _fcgi.py
     9</p>
     10}}}
     11
     12== Simple Apache configuration ==
     13
     14There are two FastCGI modules commonly available for Apache: `mod_fastcgi` and
     15`mod_fcgid`.  The `FastCgiIpcDir` and `FastCgiConfig` directives discussed
     16below are `mod_fastcgi` directives; the `DefaultInitEnv` is a `mod_fcgid`
     17directive.
     18
     19For `mod_fastcgi`, add the following to an appropriate Apache configuration
     20file:
    1421{{{
    1522# Enable fastcgi for .fcgi files
     
    2229LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
    2330}}}
    24 デフォルトの設定に問題がなければ、 `FastCgiIpcDir` の設定は必須ではありません。 `LoadModule` の行は `IfModule` グループの後になければいけないことに注意して下さい。
    25 
    26 `ScriptAlias` を設定するもしくは似たオプションが TracCgi で説明されていますが、
    27 `trac.cgi` の代わりに `trac.fcgi` を呼びます。
    28 
    29 `TRAC_ENV` を以下のように設定することができます:
     31Setting `FastCgiIpcDir` is optional if the default is suitable. Note that the `LoadModule` line must be after the `IfModule` group.
     32
     33Configure `ScriptAlias` or similar options as described in TracCgi, but
     34calling `trac.fcgi` instead of `trac.cgi`.
     35
     36You can set up the `TRAC_ENV` as an overall default:
    3037{{{
    3138FastCgiConfig -initial-env TRAC_ENV=/path/to/env/trac
    3239}}}
    3340
    34 もしくは複数の Trac プロジェクトを扱っているときは、このように設定します:
     41Or you can serve multiple Trac projects in a directory like:
    3542{{{
    3643FastCgiConfig -initial-env TRAC_ENV_PARENT_DIR=/parent/dir/of/projects
    3744}}}
    3845
    39 これらの設定は、 `mod_fcgid` では動きません。似ていますが
    40 `mod_fcgid` での部分的な解決策は以下の通りになります:
     46But neither of these will work for `mod_fcgid`.  A similar but partial
     47solution for `mod_fcgid` is:
    4148{{{
    4249DefaultInitEnv TRAC_ENV /path/to/env/trac/
    4350}}}
    44 しかし、これは `Directory` や `Location` コンテキストで使用することができません。
    45 よって、複数のプロジェクトに対応するのは難しくなります。
    46 
    47 これらのモジュールの両方 (同様に [http://www.lighttpd.net/ lighttpd] と CGI も) で動かすよりよい方法は、
    48 `trac.fcgi` に以下の値を設定することです。
    49 Web サーバに環境変数を設定する必要がなくなります。例:
     51But this cannot be used in `Directory` or `Location` context, which makes it
     52difficult to support multiple projects.
     53
     54A better method which works for both of these modules (and for  [http://www.lighttpd.net/ lighttpd] and CGI as well), because it involves
     55no server configuration settings for environment variables, is to set one
     56of the variables in `trac.fcgi`, e.g.:
    5057{{{
    5158import os
     
    5865}}}
    5966
    60 プロジェクトごとの `ScriptAliases` と `.fcgi` スクリプトを設定すれば、
    61 この方法を使用して複数のプロジェクトに対応することができます。
    62 `trac.fcgi` をコピーして、ファイル名を適切に変更し、上記のコードをそれぞれのスクリプトに追記します。
    63 
    64 == 単純な Lighttpd の設定 ==
    65 
    66 FastCGI フロントエンドは最初 [http://www.lighttpd.net/ lighttpd] のような、 Apache 以外の Web サーバのために開発されました。
    67 
    68 lighttpd はセキュアで高速で、規格に準拠したとても柔軟な Web サーバで、高いパフォーマンスの環境で最適化されます。
    69 他の Web サーバに比べて CPU や、メモリの占有率がとても少ないです。
    70 
    71 `trac.fcgi` を lighttpd で使用するためには、 lighttpd.conf に以下の行を追加します:
     67Using this method, different projects can be supported by using different
     68`.fcgi` scripts with different `ScriptAliases`, copying and appropriately
     69renaming `trac.fcgi` and adding the above code to create each such script.
     70
     71See [https://coderanger.net/~coderanger/httpd/fcgi_example.conf this fcgid example config] which uses a !ScriptAlias directive with trac.fcgi with a trailing / like this:
     72{{{
     73ScriptAlias / /srv/tracsite/cgi-bin/trac.fcgi/
     74}}}
     75
     76== Simple Cherokee Configuration ==
     77
     78Configuration wanted.
     79
     80== Simple Lighttpd Configuration ==
     81
     82The FastCGI front-end was developed primarily for use with alternative webservers, such as [http://www.lighttpd.net/ lighttpd].
     83
     84lighttpd is a secure, fast, compliant and very flexible web-server that has been optimized for high-performance
     85environments.  It has a very low memory footprint compared to other web servers and takes care of CPU load.
     86
     87For using `trac.fcgi` with lighttpd add the following to your lighttpd.conf:
    7288{{{
    7389fastcgi.server = ("/trac" =>
     
    8399}}}
    84100
    85 動かしたい Trac のインスタンス毎に `fastcgi.server` のエントリを追加する必要があります。別の方法として、、上記の `TRAC_ENV` の代わりに `TRAC_ENV_PARENT_DIR` を使用でき、
    86 `lighttpd.conf` に設定する代わりに `trac.fcgi` ファイルに
    87 `bin-environment` (上記の Apache の設定 に書かれています) の2つのうちのどちらかを設定します。
    88 
    89 lighttpd で2つのプロジェクトを動かすには、 `lighttpd.conf` に以下の設定を追加します:
     101Note that you will need to add a new entry to `fastcgi.server` for each separate Trac instance that you wish to run. Alternatively, you may use the `TRAC_ENV_PARENT_DIR` variable instead of `TRAC_ENV` as described above,
     102and you may set one of the two in `trac.fcgi` instead of in `lighttpd.conf`
     103using `bin-environment` (as in the section above on Apache configuration).
     104
     105For using two projects with lighttpd add the following to your `lighttpd.conf`:
    90106{{{
    91107fastcgi.server = ("/first" =>
     
    109125                )
    110126}}}
    111 各フィールドの値が異なることに注意して下さい。もし `.fcgi` スクリプトに
    112 環境変数を設定するほうが好ましい場合は、 `trac.fcgi` をコピー / 名前変更をして下さい。例として、
    113 `first.fcgi` と `second.fcgi` が上記の設定では参照されるようにします。
    114 上記の設定で、両方のプロジェクトが 同じ `trac.fcgi` スクリプトで起動していても、
    115 異なるプロセスになることに注意して下さい。
     127Note that field values are different.  If you prefer setting the environment
     128variables in the `.fcgi` scripts, then copy/rename `trac.fcgi`, e.g., to
     129`first.fcgi` and `second.fcgi`, and reference them in the above settings.
     130Note that the above will result in different processes in any event, even
     131if both are running from the same `trac.fcgi` script.
    116132{{{
    117133#!html
    118134<p style="background: #fdc; border: 2px solid #d00; font-style: italic; padding: 0 .5em; margin: 1em 0;">
    119 <strong>Note from c00i90wn:</strong> server.modules をロードする順番はとても重要です。もし、 mod_auth が mod_fastcgi より <strong> 先に </strong> ロードされる設定になっていない場合、サーバはユーザの認証に失敗します。
     135<strong>Note from c00i90wn:</strong> It's very important the order on which server.modules are loaded, if mod_auth is not loaded <strong>BEFORE</strong> mod_fastcgi, then the server will fail to authenticate the user.
    120136</p>
    121137}}}
    122 認証のために lighttpd.conf の 'server.modules' 中で mod_auth を有効にして、 auth.backend と認証方法を選択して下さい:
     138For authentication you should enable mod_auth in lighttpd.conf 'server.modules', select auth.backend and auth rules:
    123139{{{
    124140server.modules              = (
     
    158174
    159175}}}
    160 パスワードファイルがない場合、 lighttpd (確認したバージョンは 1.4.3) が停止するので注意して下さい。
    161 
    162 バージョン 1.3.16 以前では lighttpd は 'valid-user' をサポートしていないので注意してください。
    163 
    164 条件付の設定は静的リソースをマッピングするときに便利です。例として FastCGI を経由せずに直接イメージファイルや CSS を参照するときなどです。:
     176Note that lighttpd (I use version 1.4.3) stopped if password file doesn't exist.
     177
     178Note that lighttpd doesn't support 'valid-user' in versions prior to 1.3.16.
     179
     180Conditional configuration is also useful for mapping static resources, i.e. serving out images and CSS directly instead of through FastCGI:
    165181{{{
    166182# Aliasing functionality is needed
     
    186202}
    187203}}}
    188 複数のプロジェクトのそれぞれにエイリアスを作れば、複数のプロジェクトを動かすのは技術的には簡単です。 fastcgi.server を条件ブロックの中で宣言しラッピングします。
    189 複数のプロジェクトをハンドルするもう一つの方法があります。 TRAC_ENV_PARENT_DIR を TRAC_ENV の代わりに使用し、グローバルの認証機構を使用します。サンプルを見てみましょう:
     204The technique can be easily adapted for use with multiple projects by creating aliases for each of them, and wrapping the fastcgi.server declarations inside conditional configuration blocks.
     205Also there is another way to handle multiple projects and it's to use TRAC_ENV_PARENT_DIR instead of TRAC_ENV and use global auth, let's see an example:
    190206{{{
    191207#  This is for handling multiple projects
     
    217233}}}
    218234
    219 lighttpd では環境変数の LC_TIME を上書きして、日付/時間のフォーマットを変更することも出来ます。
     235Changing date/time format also supported by lighttpd over environment variable LC_TIME
    220236{{{
    221237fastcgi.server = ("/trac" =>
     
    231247                 )
    232248}}}
    233 使用言語指定の詳細については [http://trac.lighttpd.net/trac/wiki/TracFaq TracFaq] の 2.13 の質問を参照して下さい。
    234 
    235 その他重要な情報、例えば、 [http://trac.lighttpd.net/trac/wiki/TracInstall lighttpd の TracInstall] や、 [wiki:TracCgi#静的なリソースをマッピングする TracCgi] などは fast-cgi 固有ではありませんが、インストールの詳細をつかむのに有用でしょう。
    236 
    237 trac-0.9 を使用している場合、[http://lists.edgewall.com/archive/trac/2005-November/005311.html 些細なバグ] について読んでください。
    238 
    239 lighttpd を再起動し、ブラウザに `http://yourhost.example.org/trac` を入力して、 Trac にアクセスして下さい。
    240 
    241 制限された権限で lighttpd を起動するにあたって気をつけること:
    242 
    243   もし、 trac.fcgi が lighttpd の設定で __server.username = "www-data"__ や __server.groupname = "www-data"__ を設定しても起動せずどうしようもないときは、 `bin-environment` セクションの `PYTHON_EGG_CACHE` を `www-data` のホームディレクトリまたは `www-data` アカウントで書き込みが可能なディレクトリに設定して下さい。 (訳注: debian 系 Linux に限定した話だと思われます。 `www-data` は lighttpd を起動するユーザに適宜読み替えてください。)
    244 
    245 
    246 == 簡単な [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeeed] の設定 ==
    247 
    248 FastCGI フロントエンドは最初 [http://www.litespeedtech.com/ LiteSpeed] のような、 Apache 以外の Web サーバのために開発されました。
    249 
    250 [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeed] Web サーバはイベント駆動、非同期型であり、Apache に代わるものとしてセキュアで拡張可能になるようにゼロからデザインされています。そして、最低限のリソースで操作できます。 [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeed] は Apache の設定ファイルから直接操作でき、ビジネスに不可欠な環境をターゲットにしています。
    251 
    252 セットアップ
    253 
    254 1) 最初に Trac プロジェクトをインストールして動作することを確認して下さい。最初のインストールでは、 "tracd" を使用します。
    255 
    256 2) このセットアップでは仮想ホストを作成します。以下、この仮想ホストのことを !TracVhost と呼びます。このチュートリアルで、先ほど作ったプロジェクトが以下の URL 経由でアクセスできると仮定します:
     249For details about languages specification see TracFaq question 2.13.
     250
     251Other important information like [http://trac.lighttpd.net/trac/wiki/TracInstall this updated TracInstall page], [wiki:TracCgi#MappingStaticResources and this] are useful for non-fastcgi specific installation aspects.
     252
     253If you use trac-0.9, read [http://lists.edgewall.com/archive/trac/2005-November/005311.html about small bug]
     254
     255Relaunch lighttpd, and browse to `http://yourhost.example.org/trac` to access Trac.
     256
     257Note about running lighttpd with reduced permissions:
     258
     259  If nothing else helps and trac.fcgi doesn't start with lighttpd settings __server.username = "www-data"__, __server.groupname = "www-data"__, then in the `bin-environment` section set `PYTHON_EGG_CACHE` to the home directory of `www-data` or some other directory accessible to this account for writing.
     260
     261
     262== Simple LiteSpeed Configuration ==
     263
     264The FastCGI front-end was developed primarily for use with alternative webservers, such as [http://www.litespeedtech.com/ LiteSpeed].
     265
     266LiteSpeed web server is an event-driven asynchronous Apache replacement designed from the ground-up to be secure, scalable, and operate with minimal resources. LiteSpeed can operate directly from an Apache config file and is targeted for business-critical environments.
     267
     268Setup
     269
     2701) Please make sure you have first have a working install of a Trac project. Test install with “tracd” first.
     271
     2722) Create a Virtual Host for this setup. From now on we will refer to this vhost as TracVhost. For this tutorial we will be assuming that your trac project will be accessible via:
    257273
    258274{{{
     
    260276}}}
    261277
    262 3) "!TracVhost → External AApps" タブへ移動し、新しい "External Application" を作成します。
     2783) Go “TracVhost → External Apps” tab and create a new “External Application”.
    263279
    264280{{{
     
    278294}}}
    279295
    280 4) (非必須) "!TracVhost → Security" タブへ移動し、新しいセキュリティ "Realm" を作成することができます。
     2964) Optional. If you need to use htpasswd based authentication. Go to “TracVhost → Security” tab and create a new security “Realm”.
    281297
    282298{{{
     
    286302}}}
    287303
    288 もし、 htpasswd ファイルを持っていない、もしくは作り方を知らない場合は、 http://sherylcanter.com/encrypt.php にアクセスし、ユーザ名:パスワード の一対を生成して下さい。
    289 
    290 5) "!PythonVhost → Contexts" へ移動し、新しい "FCGI Context" を作成します。
     304If you don’t have a htpasswd file or don’t know how to create the entries within one, go to http://sherylcanter.com/encrypt.php, to generate the user:password combos.
     305
     3065) Go to “PythonVhost → Contexts” and create a new “FCGI Context”.
    291307
    292308{{{
    293309URI: /trac/                              <--- URI path to bind to python fcgi app we created   
    294310Fast CGI App: [VHost Level] MyTractFCGI  <--- select the trac fcgi extapp we just created
    295 Realm: TracUserDB                        <--- only if (4) is set. select ream created in (4)
    296 }}}
    297 
    298 6) /fullpathto/mytracproject/conf/trac.ini を修正します。
     311Realm: TracUserDB                        <--- only if (4) is set. select realm created in (4)
     312}}}
     313
     3146) Modify /fullpathto/mytracproject/conf/trac.ini
    299315
    300316{{{
     
    305321}}}
    306322
    307 7) [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeed] を "lswsctrl restart" で再起動し、新しい Trac プロジェクトに以下の URL でアクセスします:
     3237) Restart LiteSpeed, “lswsctrl restart”, and access your new Trac project at:
    308324
    309325{{{
     
    312328
    313329----
    314 See also: TracCgi, TracModPython, TracInstall, TracGuide
     330See also TracCgi, TracModPython, TracInstall, TracGuide