Changes between Initial Version and Version 1 of TracFastCgi


Ignore:
Timestamp:
Apr 10, 2015, 1:03:53 PM (9 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracFastCgi

    v1 v1  
     1[[PageOutline]]
     2
     3= Trac を FastCGI で使用する = #TracwithFastCGI
     4
     5[http://www.fastcgi.com/ FastCGI] インターフェースを使用すると [wiki:TracModPython mod_python] や [wiki:TracModWSGI mod_wsgi] と同様に Trac を常駐させることができます。リクエスト毎に新しいプロセスを開始しなければならない CGI インターフェースよりも処理速度は速くなります。加えて、多種多様の Web サーバでサポートされています。
     6
     7Note: mod_python とは異なり、FastCGI では [http://httpd.apache.org/docs/suexec.html Apache SuEXEC] をサポートしています。つまり、Web サーバを実行しているユーザとは、異なる権限でプログラムを実行することができます。(`mod_wsgi` でサポートしている `WSGIDaemonProcess` におけるユーザ / グループと同じ効果を得ることができます)
     8
     9'''Windows 向け:''' Trac の FastCGI は Windows 環境下で動作しません。これは、`_fcgi.py` で用いられる `Socket.fromfd` が Windows では実行されないからです。もし IIS へ接続したい場合は、[trac:TracOnWindowsIisAjp AJP]/[trac:TracOnWindowsIisAjp ISAPI] に挑戦してみて下さい。
     10
     11[[PageOutline(2-3,Overview,inline)]]
     12
     13
     14== 単純な Apache の設定 == #SimpleApacheconfiguration
     15
     16Apache で利用可能な FastCGI モジュールは 2 種類あります: `mod_fastcgi` と
     17`mod_fcgid` (推奨) です。後者の方がよりメンテナンスされています。
     18
     19次の項目では、FCGI の特定のセットアップに焦点を合わせています。Apache の認証の設定方法については [wiki:TracModWSGI#ConfiguringAuthentication] を参照してください。
     20
     21CGI モジュールを使用する場合は注意してください。また、必ず Web サーバに cgi-bin フォルダの実行権限を持たせてください。 FastCGI では詳細な権限に関するエラーが出力されますが、mod_fcgid ではこの処理が行われていない場合には、不明瞭なエラーしか出力されません。(Connection reset by peer: mod_fcgid: error reading data from FastCGI server の様な)
     22
     23=== `mod_fastcgi` でのセットアップ === #setupwithmod_fastcgi
     24`mod_fastcgi` では `FastCgiIpcDir` と `FastCgiConfig` ディレクティブを使用して Apache の設定ファイルに設定を行います:
     25{{{
     26# Enable fastcgi for .fcgi files
     27# (If you're using a distro package for mod_fcgi, something like
     28# this is probably already present)
     29<IfModule mod_fastcgi.c>
     30   AddHandler fastcgi-script .fcgi
     31   FastCgiIpcDir /var/lib/apache2/fastcgi
     32</IfModule>
     33LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
     34}}}
     35デフォルトの設定に問題がなければ、 `FastCgiIpcDir` の設定は必須ではありません。 `LoadModule` の行は `IfModule` グループの後になければいけないことに注意して下さい。
     36
     37`ScriptAlias` もしくは TracCgi で説明されている類似のオプションを設定しますが、
     38`trac.cgi` の代わりに `trac.fcgi` を指定してください。
     39
     40すべてデフォルトで `TRAC_ENV` をセットアップするつもりならば、Apache の設定ファイルに以下を追加します (`FastCgiIpcDir` より下に):
     41{{{
     42FastCgiConfig -initial-env TRAC_ENV=/path/to/env/trac
     43}}}
     44
     45あるいは、以下を追加することで複数の Trac プロジェクトを提供できます:
     46{{{
     47FastCgiConfig -initial-env TRAC_ENV_PARENT_DIR=/parent/dir/of/projects
     48}}}
     49
     50=== `mod_fcgid` でのセットアップ === #Setupwithmod_fcgid
     51`ScriptAlias` を設定します。 (詳細は TracCgi を参照してください)、 ただし
     52trac.cgi` の代わりに `trac.fcgi` を呼び出します。 Note: 最後のスラッシュを忘れずに。とても重要です。
     53{{{
     54ScriptAlias /trac /path/to/www/trac/cgi-bin/trac.fcgi/
     55}}}
     56
     57`mod_fcgid` で Trac environment を設定するには `DefaultInitEnv`
     58ディレクティブを使用します。このディレクティブは `Direcotry` や `Location`
     59コンテキストで使用できないので、複数のプロジェクトを設定する場合、
     60以下に記述する Environment を設定する別の方法を試してください。
     61
     62{{{
     63DefaultInitEnv TRAC_ENV /path/to/env/trac/
     64}}}
     65
     66=== Environment を設定する別の方法 === #alternativeenvironmentsetup
     67Trac environment へのパスを設定するための、より適した方法は、パスを
     68`trac.fcgi` スクリプト自体に書き込むことです。これによってサーバの環境変数を
     69設定する必要がなくなり、どちらの !FastCgi モジュール (および
     70[http://www.lighttpd.net/ lighttpd] や CGI など) でも、動作するようになります:
     71{{{
     72import os
     73os.environ['TRAC_ENV'] = "/path/to/projectenv"
     74}}}
     75または
     76{{{
     77import os
     78os.environ['TRAC_ENV_PARENT_DIR'] = "/path/to/project/parent/dir"
     79}}}
     80
     81プロジェクトごとの `ScriptAlias` と `.fcgi` スクリプトを設定すれば、
     82起動スクリプトに `TRAC_ENV` 等を設定する方法を使用して複数のプロジェクトに対応することができます。
     83
     84この [https://coderanger.net/~coderanger/httpd/fcgi_example.conf fcgid 設定例] の通り、 !ScriptAlias ディレクティブでは末尾の / も含めて設定してください:
     85{{{
     86ScriptAlias / /srv/tracsite/cgi-bin/trac.fcgi/
     87}}}
     88
     89== Cherokee の簡単な設定 == #SimpleCherokeeConfiguration
     90
     91Cherokee 側の設定はとても簡単です。 Trac を SCGI プロセスとして起動できるかどうかのみ知っている必要があります。
     92Cherokee が起動していないときにはいつでも、 Cherokee が Trac を切り離せるようにすることによって、 Trac を手動で起動することも、いっそのこと自動的に起動することもできます。
     93最初に、ローカルのインタプリタである cherokee-admin で information source を設定します。
     94
     95{{{
     96Host:
     97localhost:4433
     98
     99Interpreter:
     100/usr/bin/tracd —single-env —daemonize —protocol=scgi —hostname=localhost —port=4433 /path/to/project/
     101}}}
     102
     103もしそのポート番号に到達できなければ、インタプリタコマンドは起動されたことになります。information source の定義において、 ''ローカルインタプリタ'' の代わりに、 ''リモートホスト'' を ''information source'' として使用するならば、 spawner を手動で起動する必要があることを覚えておいてください。
     104
     105そして、 Trac にアクセスするために SCGI ハンドラによって管理される新しいルールを作成しなければなりません。このルールは例えば、 trac.example.net という新しい仮想サーバ内で作成し、 2 つのルールのみを必要とします。 '''デフォルト''' ルールは以前に作成された information source に関する SCGI ハンドラで使用されます。
     1062 つ目のルールは Trac のインタフェースを正しく表示するために必要ないくつかの静的ファイルを扱うために設定します。ルールを ''/common'' の ''ディレクトリルール'' として作成し、 ''静的ファイル'' のハンドラを適切なファイルをポイントする ''ドキュメントルート'' と共に設定するだけです: ''$TRAC_LOCAL/htdocs/'' ($TRAC_LOCAL はユーザ又はローカル Trac リソース を置いたシステム管理者により定義されたディレクトリです)
     107
     108Note:\\
     109tracd プロセスが起動しない場合や cherokee が 503 エラーページを表示する場合、 [http://trac.saddi.com/flup python-flup] がインストールされていない可能性があります。\\
     110Python-flup は SCGI の能力を trac に与える従属関係にあります。 debian 基本システムからインストールできます:
     111{{{
     112sudo apt-get install python-flup
     113}}}
     114
     115
     116== Lighttpd の簡単な設定 == #SimpleLighttpdConfiguration
     117
     118FastCGI フロントエンドは最初 [http://www.lighttpd.net/ lighttpd] のような、 Apache 以外の Web サーバのために開発されました。
     119
     120lighttpd はセキュアで高速で、規格に準拠したとても柔軟な Web サーバで、高いパフォーマンスの環境で最適化されます。
     121他の Web サーバに比べて CPU や、メモリの占有率がとても少ないです。
     122
     123`trac.fcgi`(0.11 以前) / fcgi_frontend.py (0.11) を lighttpd で使用するためには、 lighttpd.conf に以下の行を追加します:
     124{{{
     125#var.fcgi_binary="/usr/bin/python /path/to/fcgi_frontend.py" # 0.11 if installed with easy_setup, it is inside the egg directory
     126var.fcgi_binary="/path/to/cgi-bin/trac.fcgi" # 0.10 name of prior fcgi executable
     127fastcgi.server = ("/trac" =>
     128
     129                   ("trac" =>
     130                     ("socket" => "/tmp/trac-fastcgi.sock",
     131                      "bin-path" => fcgi_binary,
     132                      "check-local" => "disable",
     133                      "bin-environment" =>
     134                        ("TRAC_ENV" => "/path/to/projenv")
     135                     )
     136                   )
     137                 )
     138}}}
     139
     140動かしたい Trac のインスタンス毎に `fastcgi.server` のエントリを追加する必要があります。別の方法として、上記の `TRAC_ENV` の代わりに `TRAC_ENV_PARENT_DIR` を使用でき、
     141`lighttpd.conf` に設定する代わりに `trac.fcgi` ファイルに
     142`bin-environment` (上記の Apache の設定 に書かれています) の2つのうちのどちらかを設定します。
     143
     144Note: lighttpd には 'SCRIPT_NAME' と 'PATH_INFO' に関するバグがあります。例として、 fastcgi.server の uri が '/trac' とするところを '/' としてしまいます。 ([trac:#2418 本家チケット 2418] 参照) このバグは lighttpd 1.4.23 以降で修正されています。 fastcgi.server のパラメータとして、 `"fix-root-scriptname" => "enable"` を追加する必要があるでしょう。
     145
     146lighttpd で2つのプロジェクトを動かすには、 `lighttpd.conf` に以下の設定を追加します:
     147{{{
     148fastcgi.server = ("/first" =>
     149                   ("first" =>
     150                    ("socket" => "/tmp/trac-fastcgi-first.sock",
     151                     "bin-path" => fcgi_binary,
     152                     "check-local" => "disable",
     153                     "bin-environment" =>
     154                       ("TRAC_ENV" => "/path/to/projenv-first")
     155                    )
     156                  ),
     157                  "/second" =>
     158                    ("second" =>
     159                    ("socket" => "/tmp/trac-fastcgi-second.sock",
     160                     "bin-path" => fcgi_binary,
     161                     "check-local" => "disable",
     162                     "bin-environment" =>
     163                       ("TRAC_ENV" => "/path/to/projenv-second")
     164                    )
     165                  )
     166                )
     167}}}
     168Note: 各フィールドの値が異なることに注意して下さい。もし、
     169`.fcgi` スクリプト内の環境変数を設定する方が好ましいならば、 `trac.fcgi` スクリプトを
     170例えば、 `first.fcgi` や `second.fcgi` というようにコピー / リネームして、上記設定の中でこれらのスクリプトを参照するようにしてください。
     171両方のプロジェクトが同じ `trac.fcgi` スクリプトから起動しているとしても、
     172異なるプロセスになることに注意して下さい。
     173
     174{{{
     175#!div class=important
     176'''Note''': server.modules をロードする順番はとても重要です。もし、 mod_auth が mod_fastcgi より '''先に''' mod_auth がロードされない設定になっていない場合、サーバはユーザ認証に失敗します。
     177}}}
     178
     179認証のために lighttpd.conf の 'server.modules' 中で mod_auth を有効にして、 auth.backend と認証方法を選択して下さい:
     180{{{
     181server.modules              = (
     182...
     183  "mod_auth",
     184...
     185)
     186
     187auth.backend               = "htpasswd"
     188
     189# Separated password files for each project
     190# See "Conditional Configuration" in
     191# http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/configuration.txt
     192
     193$HTTP["url"] =~ "^/first/" {
     194  auth.backend.htpasswd.userfile = "/path/to/projenv-first/htpasswd.htaccess"
     195}
     196$HTTP["url"] =~ "^/second/" {
     197  auth.backend.htpasswd.userfile = "/path/to/projenv-second/htpasswd.htaccess"
     198}
     199
     200# Enable auth on trac URLs, see
     201# http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/authentication.txt
     202
     203auth.require = ("/first/login" =>
     204                ("method"  => "basic",
     205                 "realm"   => "First project",
     206                 "require" => "valid-user"
     207                ),
     208                "/second/login" =>
     209                ("method"  => "basic",
     210                 "realm"   => "Second project",
     211                 "require" => "valid-user"
     212                )
     213               )
     214
     215
     216}}}
     217Note: パスワードファイルがない場合、 lighttpd (確認したバージョンは 1.4.3) が停止するので注意して下さい。
     218
     219Note: バージョン 1.3.16 以前では lighttpd は 'valid-user' をサポートしていないので注意してください。
     220
     221条件付の設定は静的リソースをマッピングするときに便利です。例として FastCGI を経由せずに直接イメージファイルや CSS を参照するときなどです:
     222{{{
     223# Aliasing functionality is needed
     224server.modules += ("mod_alias")
     225
     226# Set up an alias for the static resources
     227alias.url = ("/trac/chrome/common" => "/usr/share/trac/htdocs")
     228
     229# Use negative lookahead, matching all requests that ask for any resource under /trac, EXCEPT in
     230# /trac/chrome/common, and use FastCGI for those
     231$HTTP["url"] =~ "^/trac(?!/chrome/common)" {
     232# Even if you have other fastcgi.server declarations for applications other than Trac, do NOT use += here
     233fastcgi.server = ("/trac" =>
     234                   ("trac" =>
     235                     ("socket" => "/tmp/trac-fastcgi.sock",
     236                      "bin-path" => fcgi_binary,
     237                      "check-local" => "disable",
     238                      "bin-environment" =>
     239                        ("TRAC_ENV" => "/path/to/projenv")
     240                     )
     241                   )
     242                 )
     243}
     244}}}
     245複数のプロジェクトのそれぞれにエイリアスを作れば、複数のプロジェクトを動かすのは技術的には簡単です。 fastcgi.server を条件ブロックの中で宣言しラッピングします。
     246複数のプロジェクトをハンドルするもう一つの方法があります。 TRAC_ENV_PARENT_DIR を TRAC_ENV の代わりに使用し、グローバルの認証機構を使用します。サンプルを見てみましょう:
     247{{{
     248#  This is for handling multiple projects
     249  alias.url       = ( "/trac/" => "/path/to/trac/htdocs/" )
     250
     251  fastcgi.server += ("/projects"  =>
     252                      ("trac" =>
     253                        (
     254                          "socket" => "/tmp/trac.sock",
     255                          "bin-path" => fcgi_binary,
     256                          "check-local" => "disable",
     257                          "bin-environment" =>
     258                            ("TRAC_ENV_PARENT_DIR" => "/path/to/parent/dir/of/projects/" )
     259                        )
     260                      )
     261                    )
     262#And here starts the global auth configuration
     263  auth.backend = "htpasswd"
     264  auth.backend.htpasswd.userfile = "/path/to/unique/htpassword/file/trac.htpasswd"
     265  $HTTP["url"] =~ "^/projects/.*/login$" {
     266    auth.require = ("/" =>
     267                     (
     268                       "method"  => "basic",
     269                       "realm"   => "trac",
     270                       "require" => "valid-user"
     271                     )
     272                   )
     273  }
     274}}}
     275
     276lighttpd では環境変数の LC_TIME を上書きして、日付/時間のフォーマットを変更することも出来ます。
     277{{{
     278fastcgi.server = ("/trac" =>
     279                   ("trac" =>
     280                     ("socket" => "/tmp/trac-fastcgi.sock",
     281                      "bin-path" => fcgi_binary,
     282                      "check-local" => "disable",
     283                      "bin-environment" =>
     284                        ("TRAC_ENV" => "/path/to/projenv",
     285                        "LC_TIME" => "ru_RU")
     286                     )
     287                   )
     288                 )
     289}}}
     290使用言語指定の詳細については [http://trac.lighttpd.net/trac/wiki/TracFaq TracFaq] の 2.13 の質問を参照して下さい。
     291
     292[wiki:TracInstall#MappingStaticResources 静的なリソースのマッピングに関する事] の様な他の重要な情報は、fastcgi 以外でもインストールの詳細をつかむのに有効です。
     293]
     294
     295lighttpd を再起動し、ブラウザに `http://yourhost.example.org/trac` を入力して、 Trac にアクセスして下さい。
     296
     297制限された権限で lighttpd を起動するにあたって気をつけること:
     298
     299もし、 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 を起動するユーザに適宜読み替えてください。)
     300
     301
     302== !LiteSpeed の簡単な設定 == #SimpleLighttpdConfiguration
     303
     304FastCGI フロントエンドは最初 [http://www.litespeedtech.com/ LiteSpeed] のような、 Apache 以外の Web サーバのために開発されました。
     305
     306!LiteSpeed Web サーバはイベント駆動、非同期型であり、 Apache に代わるものとしてセキュアで拡張可能になるようにゼロからデザインされています。そして、最低限のリソースで操作できます。 !LiteSpeed は Apache の設定ファイルから直接操作でき、ビジネスに不可欠な環境をターゲットにしています。
     307
     308 1. 最初に Trac プロジェクトをインストールして動作することを確認して下さい。最初のインストールでは、 "tracd" を使用します
     309
     310 2. このセットアップでは仮想ホストを作成します。以下、この仮想ホストのことを !TracVhost と呼びます。このチュートリアルで、先ほど作ったプロジェクトが以下の URL 経由でアクセスできると仮定します:
     311
     312{{{
     313http://yourdomain.com/trac/
     314}}}
     315
     316 3. "!TracVhost → External Apps" タブへ移動し、新しい "External Application" を作成します
     317
     318{{{
     319Name: MyTracFCGI
     320Address: uds://tmp/lshttpd/mytracfcgi.sock
     321Max Connections: 10
     322Environment: TRAC_ENV=/fullpathto/mytracproject/ <--- path to root folder of trac project
     323Initial Request Timeout (secs): 30
     324Retry Timeout (secs): 0
     325Persistent Connection   Yes
     326Connection Keepalive Timeout: 30
     327Response Bufferring: No
     328Auto Start: Yes
     329Command: /usr/share/trac/cgi-bin/trac.fcgi  <--- path to trac.fcgi
     330Back Log: 50
     331Instances: 10
     332}}}
     333
     334 4. (非必須) htpasswd ベースの認証を使用するならば、 "!TracVhost → Security" タブへ移動し、新しいセキュリティ "Realm" を作成することができます
     335
     336{{{
     337DB Type: Password File
     338Realm Name: MyTracUserDB               <--- any name you wish and referenced later
     339User DB Location: /fullpathto/htpasswd <--- path to your htpasswd file
     340}}}
     341
     342もし、 htpasswd ファイルを持っていない、もしくは作り方を知らない場合は、 http://sherylcanter.com/encrypt.php にアクセスし、ユーザ名:パスワード の一対を生成して下さい。
     343
     344 5. "!PythonVhost → Contexts" へ移動し、新しい "FCGI Context" を作成します
     345
     346{{{
     347URI: /trac/                              <--- URI path to bind to python fcgi app we created
     348Fast CGI App: [VHost Level] MyTractFCGI  <--- select the trac fcgi extapp we just created
     349Realm: TracUserDB                        <--- only if (4) is set. select realm created in (4)
     350}}}
     351
     352 6. /fullpathto/mytracproject/conf/trac.ini を修正します
     353
     354{{{
     355#find/set base_rul, url, and link variables
     356base_url = http://yourdomain.com/trac/ <--- base url to generate correct links to
     357url = http://yourdomain.com/trac/      <--- link of project
     358link = http://yourdomain.com/trac/     <--- link of graphic logo
     359}}}
     360
     361 7. !LiteSpeed を "lswsctrl restart" で再起動し、新しい Trac プロジェクトに以下の URL でアクセスします:
     362
     363{{{
     364http://yourdomain.com/trac/
     365}}}
     366
     367
     368== Nginx 簡単な設定 == #SimpleNginxConfiguration
     369
     370Nginx は FastCGI プロセスを生成することはできませんが、伝達することができます。そのため、 Trac を独立して FastCGI サーバを開始する必要があります。
     371
     372 1. 基本認証を行う Nginx の設定 - 0.6.32 で動作することを確認しました
     373{{{
     374    server {
     375        listen       10.9.8.7:443;
     376        server_name  trac.example;
     377
     378        ssl                  on;
     379        ssl_certificate      /etc/ssl/trac.example.crt;
     380        ssl_certificate_key  /etc/ssl/trac.example.key;
     381
     382        ssl_session_timeout  5m;
     383
     384        ssl_protocols  SSLv2 SSLv3 TLSv1;
     385        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
     386        ssl_prefer_server_ciphers   on;
     387
     388        # (Or ``^/some/prefix/(.*)``.
     389        if ($uri ~ ^/(.*)) {
     390             set $path_info /$1;
     391        }
     392
     393        # it makes sense to serve static resources through Nginx
     394        location /chrome/ {
     395             alias /home/trac/instance/static/htdocs/;
     396        }
     397
     398        # You can copy this whole location to ``location [/some/prefix]/login``
     399        # and remove the auth entries below if you want Trac to enforce
     400        # authorization where appropriate instead of needing to authenticate
     401        # for accessing the whole site.
     402        # (Or ``location /some/prefix``.)
     403        location / {
     404            auth_basic            "trac realm";
     405            auth_basic_user_file /home/trac/htpasswd;
     406
     407            # socket address
     408            fastcgi_pass   unix:/home/trac/run/instance.sock;
     409
     410            # python - wsgi specific
     411            fastcgi_param HTTPS on;
     412
     413            ## WSGI REQUIRED VARIABLES
     414            # WSGI application name - trac instance prefix.
     415            # (Or ``fastcgi_param  SCRIPT_NAME  /some/prefix``.)
     416            fastcgi_param  SCRIPT_NAME        "";
     417            fastcgi_param  PATH_INFO          $path_info;
     418
     419            ## WSGI NEEDED VARIABLES - trac warns about them
     420            fastcgi_param  REQUEST_METHOD     $request_method;
     421            fastcgi_param  SERVER_NAME        $server_name;
     422            fastcgi_param  SERVER_PORT        $server_port;
     423            fastcgi_param  SERVER_PROTOCOL    $server_protocol;
     424            fastcgi_param  QUERY_STRING       $query_string;
     425
     426            # For Nginx authentication to work - do not forget to comment these
     427            # lines if not using Nginx for authentication
     428            fastcgi_param  AUTH_USER          $remote_user;
     429            fastcgi_param  REMOTE_USER        $remote_user;
     430
     431            # for ip to work
     432            fastcgi_param REMOTE_ADDR         $remote_addr;
     433
     434            # For attchments to work
     435            fastcgi_param    CONTENT_TYPE     $content_type;
     436            fastcgi_param    CONTENT_LENGTH   $content_length;
     437        }
     438    }
     439}}}
     440
     441 2. trac.fcgi の変更:
     442
     443{{{
     444#!/usr/bin/env python
     445import os
     446sockaddr = '/home/trac/run/instance.sock'
     447os.environ['TRAC_ENV'] = '/home/trac/instance'
     448
     449try:
     450     from trac.web.main import dispatch_request
     451     import trac.web._fcgi
     452
     453     fcgiserv = trac.web._fcgi.WSGIServer(dispatch_request,
     454          bindAddress = sockaddr, umask = 7)
     455     fcgiserv.run()
     456
     457except SystemExit:
     458    raise
     459except Exception, e:
     460    print 'Content-Type: text/plain\r\n\r\n',
     461    print 'Oops...'
     462    print
     463    print 'Trac detected an internal error:'
     464    print
     465    print e
     466    print
     467    import traceback
     468    import StringIO
     469    tb = StringIO.StringIO()
     470    traceback.print_exc(file=tb)
     471    print tb.getvalue()
     472
     473}}}
     474
     475 3. nginx をリロードし、 trac.fcgi をこのように起動します:
     476
     477{{{
     478trac@trac.example ~ $ ./trac-standalone-fcgi.py
     479}}}
     480
     481上記設定は以下の条件だと仮定します:
     482 * trac のインスタンスを実行するためのユーザ名を 'trac' とします。ホームディレクトリに trac Environment をおきます
     483 * Trac environment は `/home/trac/instance` に配置します
     484 * `/home/trac/htpasswd` に認証情報が含まれています
     485 * `/home/trac/run` は nginx を起動しているグループが所有しています
     486  * Linux を使用しているならば、 `/home/trac/run` に (`chmod g+s run`) を設定します
     487  * [trac:#7239 本家チケット 7239] のパッチを適用し、ソケットファイルのパーミッションをそのつど修正しなければいけません
     488
     489残念ですが、 nginx は fastcgi_pass ディレクティブ内の変数展開をサポートしていません。
     490したがって、 1 つのサーバーブロックから複数の trac インスタンスを起動することができません。
     491
     492セキュリティ面で不安があるならば、 各 Trac インスタンスを別々のユーザで起動してください。
     493
     494Trac を FCGI の外部アプリケーションとして起動するもう一つの方法は、[trac:#6224 本家チケット 6224] を参照して下さい。
     495
     496----
     497See also:  TracGuide, TracInstall, [wiki:TracModWSGI ModWSGI], [wiki:TracCgi CGI], [wiki:TracModPython ModPython], [trac:TracNginxRecipe TracNginxRecipe]