XPressME Integration Kit

Trac

Version 1 から Version 2 における更新: TracFastCgi

差分発生行の前後
Ignore:
Timestamp:
Nov 29, 2010, 3:25:29 PM (13 years 前)
Author:
trac (IP: 127.0.0.1)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracFastCgi

    v1 v2  
    1 = Trac を FastCGI で使用する = #TracwithFastCGI 
    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 {{{ 
    6 #!html 
    7 <p style="background: #fdc; border: 2px solid #d00; font-style: italic; padding: 0 .5em; margin: 1em 0;"> 
    8 <strong>Windows 向けの Note:</strong> Trac の FCGI は Windows では使用できません。 Windows では_fcgi.py で使用されている Socket.fromfd が実装されていないためです。 
    9 </p> 
    10 }}} 
    11  
    12 == 単純な Apache の設定 == #SimpleApacheconfiguration 
    13  
    14 Apache で利用可能な FastCGI モジュールは 2 種類あります: `mod_fastcgi` と  
    15 `mod_fcgid` です。これ以降に書かれている `FastCgiIpcDir` と `FastCgiConfig` ディレクティブ 
    16 は `mod_fastcgi` のディレクティブです; `DefaultInitEnv` は `mod_fcgid`  
    17 のディレクティブです。 
    18  
    19 `mod_fastcgi` では、 Apache の設定ファイルに以下の設定を追記します。 
    20 ファイル: 
     1= Trac with FastCGI = 
     2 
     3[http://www.fastcgi.com/ FastCGI] interface allows Trac to remain resident much like with [wiki:TracModPython mod_python]. It is faster than external CGI interfaces which must start a new process for each request. However, unlike mod_python, FastCGI supports [http://httpd.apache.org/docs/suexec.html Apache SuEXEC], i.e. run with different permissions than web server. Additionally, it is supported by much wider variety of web servers. 
     4 
     5'''Note for Windows:''' Trac's FastCGI does not run under Windows, as Windows does not implement `Socket.fromfd`, which is used by `_fcgi.py`. If you want to connect to IIS, you may want to try [trac:TracOnWindowsIisAjp AJP]. 
     6 
     7== Simple Apache configuration == 
     8 
     9There are two FastCGI modules commonly available for Apache: `mod_fastcgi` and 
     10`mod_fcgid` (preferred). The latter is more up-to-date. 
     11 
     12==== setup with `mod_fastcgi` ==== 
     13`mod_fastcgi` uses `FastCgiIpcDir` and `FastCgiConfig` directives that should be added to an appropriate Apache configuration file: 
    2114{{{ 
    2215# Enable fastcgi for .fcgi files 
     
    2922LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so 
    3023}}} 
    31 デフォルトの設定に問題がなければ、 `FastCgiIpcDir` の設定は必須ではありません。 `LoadModule` の行は `IfModule` グループの後になければいけないことに注意して下さい。 
    32  
    33 `ScriptAlias` を設定するもしくは似たオプションが TracCgi で説明されていますが、  
    34 `trac.cgi` の代わりに `trac.fcgi` を呼びます。 
    35  
    36 `TRAC_ENV` を以下のように設定することができます: 
     24Setting `FastCgiIpcDir` is optional if the default is suitable. Note that the `LoadModule` line must be after the `IfModule` group. 
     25 
     26Configure `ScriptAlias` or similar options as described in TracCgi, but 
     27calling `trac.fcgi` instead of `trac.cgi`. 
     28 
     29You can set up the `TRAC_ENV` as an overall default: 
    3730{{{ 
    3831FastCgiConfig -initial-env TRAC_ENV=/path/to/env/trac 
    3932}}} 
    4033 
    41 もしくは複数の Trac プロジェクトを扱っているときは、このように設定します: 
     34Or you can serve multiple Trac projects in a directory like: 
    4235{{{ 
    4336FastCgiConfig -initial-env TRAC_ENV_PARENT_DIR=/parent/dir/of/projects 
    4437}}} 
    4538 
    46 これらの設定は、 `mod_fcgid` では動きません。似ていますが  
    47 `mod_fcgid` での部分的な解決策は以下の通りになります: 
     39==== setup with `mod_fcgid` ==== 
     40Configure `ScriptAlias` (see TracCgi for details), but call `trac.fcgi` 
     41instead of `trac.cgi`. Note that slash at the end - it is important. 
     42{{{ 
     43ScriptAlias /trac /path/to/www/trac/cgi-bin/trac.fcgi/ 
     44}}} 
     45 
     46To setup Trac environment for `mod_fcgid` it is necessary to use 
     47`DefaultInitEnv` directive. It cannot be used in `Directory` or 
     48`Location` context, so if you need to support multiple projects, try 
     49alternative environment setup below. 
     50 
    4851{{{ 
    4952DefaultInitEnv TRAC_ENV /path/to/env/trac/ 
    5053}}} 
    51 しかし、これは `Directory` や `Location` コンテキストで使用することができません。 
    52 よって、複数のプロジェクトに対応するのは難しくなります。 
    53  
    54 これらのモジュールの両方 (同様に [http://www.lighttpd.net/ lighttpd] と CGI も) で動かすよりよい方法は、  
    55 `trac.fcgi` に以下の値を設定することです。  
    56 Web サーバに環境変数を設定する必要がなくなります。例: 
     54 
     55==== alternative environment setup ==== 
     56A better method to specify path to Trac environment it to embed the path 
     57into `trac.fcgi` script itself. That doesn't require configuration of server 
     58environment variables, works for both FastCgi modules 
     59(and for [http://www.lighttpd.net/ lighttpd] and CGI as well): 
    5760{{{ 
    5861import os 
     
    6568}}} 
    6669 
    67 プロジェクトごとの `ScriptAliases` と `.fcgi` スクリプトを設定すれば、 
    68 この方法を使用して複数のプロジェクトに対応することができます。  
    69 `trac.fcgi` をコピーして、ファイル名を適切に変更し、上記のコードをそれぞれのスクリプトに追記します。 
    70  
    71 この [https://coderanger.net/~coderanger/httpd/fcgi_example.conf fcgid 設定例] を見たところ、 !ScriptAlias ディレクティブでは末尾の / も含めて、このように設定する: 
     70With this method different projects can be supported by using different 
     71`.fcgi` scripts with different `ScriptAliases`. 
     72 
     73See [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: 
    7274{{{ 
    7375ScriptAlias / /srv/tracsite/cgi-bin/trac.fcgi/ 
     
    7678== Simple Cherokee Configuration == 
    7779 
    78 Configuration wanted. 
    79  
    80 == 単純な Lighttpd の設定 == #SimpleLighttpdConfiguration 
    81  
    82 FastCGI フロントエンドは最初 [http://www.lighttpd.net/ lighttpd] のような、 Apache 以外の Web サーバのために開発されました。 
    83  
    84 lighttpd はセキュアで高速で、規格に準拠したとても柔軟な Web サーバで、高いパフォーマンスの環境で最適化されます。 
    85 他の Web サーバに比べて CPU や、メモリの占有率がとても少ないです。 
    86  
    87 `trac.fcgi` を lighttpd で使用するためには、 lighttpd.conf に以下の行を追加します: 
    88 {{{ 
     80The configuration on Cherokee's side is quite simple. You will only need to know that you can spawn Trac as an SCGI process. 
     81You can either start it manually, or better yet, automatically by letting Cherokee spawn the server whenever it is down. 
     82First set up an information source in cherokee-admin with a local interpreter. 
     83 
     84{{{ 
     85Host: 
     86localhost:4433 
     87 
     88Interpreter: 
     89/usr/bin/tracd —single-env —daemonize —protocol=scgi —hostname=localhost —port=4433 /path/to/project/ 
     90}}} 
     91 
     92If the port was not reachable, the interpreter command would be launched. Note that, in the definition of the information source, you will have to manually launch the spawner if you use a ''Remote host'' as ''Information source'' instead of a ''Local interpreter''. 
     93 
     94After doing this, we will just have to create a new rule managed by the SCGI handler to access Trac. It can be created in a new virtual server, trac.example.net for instance, and will only need two rules. The '''default''' one will use the SCGI handler associated to the previously created information source. 
     95The second rule will be there to serve the few static files needed to correctly display the Trac interface. Create it as ''Directory rule'' for ''/chrome/common'' and just set it to the ''Static files'' handler and with a ''Document root'' that points to the appropriate files: ''/usr/share/trac/htdocs/'' 
     96 
     97== Simple Lighttpd Configuration == 
     98 
     99The FastCGI front-end was developed primarily for use with alternative webservers, such as [http://www.lighttpd.net/ lighttpd]. 
     100 
     101lighttpd is a secure, fast, compliant and very flexible web-server that has been optimized for high-performance 
     102environments.  It has a very low memory footprint compared to other web servers and takes care of CPU load. 
     103 
     104For using `trac.fcgi`(prior to 0.11) / fcgi_frontend.py (0.11) with lighttpd add the following to your lighttpd.conf: 
     105{{{ 
     106#var.fcgi_binary="/usr/bin/python /path/to/fcgi_frontend.py" # 0.11 if installed with easy_setup, it is inside the egg directory 
     107var.fcgi_binary="/path/to/cgi-bin/trac.fcgi" # 0.10 name of prior fcgi executable 
    89108fastcgi.server = ("/trac" => 
     109    
    90110                   ("trac" => 
    91111                     ("socket" => "/tmp/trac-fastcgi.sock", 
    92                       "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     112                      "bin-path" => fcgi_binary, 
    93113                      "check-local" => "disable", 
    94114                      "bin-environment" => 
     
    99119}}} 
    100120 
    101 動かしたい Trac のインスタンス毎に `fastcgi.server` のエントリを追加する必要があります。別の方法として、、上記の `TRAC_ENV` の代わりに `TRAC_ENV_PARENT_DIR` を使用でき、  
    102 `lighttpd.conf` に設定する代わりに `trac.fcgi` ファイルに  
    103 `bin-environment` (上記の Apache の設定 に書かれています) の2つのうちのどちらかを設定します。 
    104  
    105 lighttpd で2つのプロジェクトを動かすには、 `lighttpd.conf` に以下の設定を追加します: 
     121Note 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, 
     122and you may set one of the two in `trac.fcgi` instead of in `lighttpd.conf` 
     123using `bin-environment` (as in the section above on Apache configuration). 
     124 
     125Note that lighttpd has a bug related to 'SCRIPT_NAME' and 'PATH_INFO' when the uri of fastcgi.server is '/' instead of '/trac' in this example, see #Trac2418. This should be fixed since lighttpd 1.4.23, and you may need to add `"fix-root-scriptname" => "enable"` as parameter of fastcgi.server. 
     126 
     127For using two projects with lighttpd add the following to your `lighttpd.conf`: 
    106128{{{ 
    107129fastcgi.server = ("/first" => 
    108130                   ("first" => 
    109131                    ("socket" => "/tmp/trac-fastcgi-first.sock", 
    110                      "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     132                     "bin-path" => fcgi_binary, 
    111133                     "check-local" => "disable", 
    112134                     "bin-environment" => 
     
    117139                    ("second" => 
    118140                    ("socket" => "/tmp/trac-fastcgi-second.sock", 
    119                      "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     141                     "bin-path" => fcgi_binary, 
    120142                     "check-local" => "disable", 
    121143                     "bin-environment" => 
     
    125147                ) 
    126148}}} 
    127 各フィールドの値が異なることに注意して下さい。もし `.fcgi` スクリプトに 
    128 環境変数を設定するほうが好ましい場合は、 `trac.fcgi` をコピー/名前変更をして下さい。例として、 
    129 `first.fcgi` と `second.fcgi` が上記の設定では参照されるようにします。 
    130 上記の設定で、両方のプロジェクトが 同じ `trac.fcgi` スクリプトで起動していても、 
    131 異なるプロセスになることに注意して下さい。 
    132 {{{ 
    133 #!html 
    134 <p style="background: #fdc; border: 2px solid #d00; font-style: italic; padding: 0 .5em; margin: 1em 0;"> 
    135 <strong>Note from c00i90wn:</strong> server.modules をロードする順番はとても重要です。もし、 mod_auth が mod_fastcgi より <strong> 先に </strong> ロードされる設定になっていない場合、サーバはユーザの認証に失敗します。 
    136 </p> 
    137 }}} 
    138 認証のために lighttpd.conf の 'server.modules' 中で mod_auth を有効にして、 auth.backend と認証方法を選択して下さい: 
     149Note that field values are different.  If you prefer setting the environment 
     150variables in the `.fcgi` scripts, then copy/rename `trac.fcgi`, e.g., to 
     151`first.fcgi` and `second.fcgi`, and reference them in the above settings. 
     152Note that the above will result in different processes in any event, even 
     153if both are running from the same `trac.fcgi` script. 
     154{{{ 
     155#!div class=important 
     156'''Note''' It's very important the order on which server.modules are loaded, if mod_auth is not loaded '''BEFORE''' mod_fastcgi, then the server will fail to authenticate the user. 
     157}}} 
     158For authentication you should enable mod_auth in lighttpd.conf 'server.modules', select auth.backend and auth rules: 
    139159{{{ 
    140160server.modules              = ( 
     
    174194 
    175195}}} 
    176 パスワードファイルがない場合、 lighttpd (確認したバージョンは 1.4.3) が停止するので注意して下さい。 
    177  
    178 バージョン 1.3.16 以前では lighttpd は 'valid-user' をサポートしていないので注意してください。 
    179  
    180 条件付の設定は静的リソースをマッピングするときに便利です。例として FastCGI を経由せずに直接イメージファイルや CSS を参照するときなどです。: 
     196Note that lighttpd (I use version 1.4.3) stopped if password file doesn't exist. 
     197 
     198Note that lighttpd doesn't support 'valid-user' in versions prior to 1.3.16. 
     199 
     200Conditional configuration is also useful for mapping static resources, i.e. serving out images and CSS directly instead of through FastCGI: 
    181201{{{ 
    182202# Aliasing functionality is needed 
     
    193213                   ("trac" => 
    194214                     ("socket" => "/tmp/trac-fastcgi.sock", 
    195                       "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     215                      "bin-path" => fcgi_binary, 
    196216                      "check-local" => "disable", 
    197217                      "bin-environment" => 
     
    202222} 
    203223}}} 
    204 複数のプロジェクトのそれぞれにエイリアスを作れば、複数のプロジェクトを動かすのは技術的には簡単です。 fastcgi.server を条件ブロックの中で宣言しラッピングします。 
    205 複数のプロジェクトをハンドルするもう一つの方法があります。 TRAC_ENV_PARENT_DIR を TRAC_ENV の代わりに使用し、グローバルの認証機構を使用します。サンプルを見てみましょう: 
     224The 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. 
     225Also 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: 
    206226{{{ 
    207227#  This is for handling multiple projects 
     
    212232                        ( 
    213233                          "socket" => "/tmp/trac.sock", 
    214                           "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     234                          "bin-path" => fcgi_binary, 
    215235                          "check-local" => "disable", 
    216236                          "bin-environment" => 
     
    233253}}} 
    234254 
    235 lighttpd では環境変数の LC_TIME を上書きして、日付/時間のフォーマットを変更することも出来ます。 
     255Changing date/time format also supported by lighttpd over environment variable LC_TIME 
    236256{{{ 
    237257fastcgi.server = ("/trac" => 
    238258                   ("trac" => 
    239259                     ("socket" => "/tmp/trac-fastcgi.sock", 
    240                       "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     260                      "bin-path" => fcgi_binary, 
    241261                      "check-local" => "disable", 
    242262                      "bin-environment" => 
     
    247267                 ) 
    248268}}} 
    249 使用言語指定の詳細については [http://trac.lighttpd.net/trac/wiki/TracFaq TracFaq] の 2.13 の質問を参照して下さい。 
    250  
    251 その他重要な情報、例えば、 [http://trac.lighttpd.net/trac/wiki/TracInstall lighttpd の TracInstall] や、 [wiki:TracCgi#静的なリソースをマッピングする TracCgi] などは fast-cgi 固有ではありませんが、インストールの詳細をつかむのに有用でしょう。 
    252  
    253 trac-0.9 を使用している場合、[http://lists.edgewall.com/archive/trac/2005-November/005311.html 些細なバグ] について読んでください。 
    254  
    255 lighttpd を再起動し、ブラウザに `http://yourhost.example.org/trac` を入力して、 Trac にアクセスして下さい。 
    256  
    257 制限された権限で lighttpd を起動するにあたって気をつけること: 
    258  
    259   もし、 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 を起動するユーザに適宜読み替えてください。) 
    260  
    261  
    262 == 簡単な [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeeed] の設定 == #SimpleLighttpdConfiguration 
    263  
    264 FastCGI フロントエンドは最初 [http://www.litespeedtech.com/ LiteSpeed] のような、 Apache 以外の Web サーバのために開発されました。 
    265  
    266 [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeed] Web サーバはイベント駆動、非同期型であり、Apache に代わるものとしてセキュアで拡張可能になるようにゼロからデザインされています。そして、最低限のリソースで操作できます。 [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeed] は Apache の設定ファイルから直接操作でき、ビジネスに不可欠な環境をターゲットにしています。 
    267  
    268 セットアップ 
    269  
    270 1) 最初に Trac プロジェクトをインストールして動作することを確認して下さい。最初のインストールでは、 "tracd" を使用します。 
    271  
    272 2) このセットアップでは仮想ホストを作成します。以下、この仮想ホストのことを !TracVhost と呼びます。このチュートリアルで、先ほど作ったプロジェクトが以下の URL 経由でアクセスできると仮定します: 
     269For details about languages specification see [trac:TracFaq TracFaq] question 2.13. 
     270 
     271Other 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. 
     272 
     273If you use trac-0.9, read [http://lists.edgewall.com/archive/trac/2005-November/005311.html about small bug] 
     274 
     275Relaunch lighttpd, and browse to `http://yourhost.example.org/trac` to access Trac. 
     276 
     277Note about running lighttpd with reduced permissions: 
     278 
     279  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. 
     280 
     281 
     282== Simple !LiteSpeed Configuration == 
     283 
     284The FastCGI front-end was developed primarily for use with alternative webservers, such as [http://www.litespeedtech.com/ LiteSpeed]. 
     285 
     286!LiteSpeed 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. 
     287 
     288=== Setup === 
     289 
     290 1. Please make sure you have first have a working install of a Trac project. Test install with “tracd” first. 
     291 
     292 2. 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: 
    273293 
    274294{{{ 
     
    276296}}} 
    277297 
    278 3) "!TracVhost → External AApps" タブへ移動し、新しい "External Application" を作成します。 
     298 3. Go “!TracVhost → External Apps” tab and create a new “External Application”. 
    279299 
    280300{{{ 
     
    294314}}} 
    295315 
    296 4) (非必須) "!TracVhost → Security" タブへ移動し、新しいセキュリティ "Realm" を作成することができます。 
     316 4. Optional. If you need to use htpasswd based authentication. Go to “!TracVhost → Security” tab and create a new security “Realm”. 
    297317 
    298318{{{ 
     
    302322}}} 
    303323 
    304 もし、 htpasswd ファイルを持っていない、もしくは作り方を知らない場合は、 http://sherylcanter.com/encrypt.php にアクセスし、ユーザ名:パスワード の一対を生成して下さい。 
    305  
    306 5) "!PythonVhost → Contexts" へ移動し、新しい "FCGI Context" を作成します。 
     324If 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. 
     325 
     326 5. Go to “!PythonVhost → Contexts” and create a new “FCGI Context”. 
    307327 
    308328{{{ 
     
    312332}}} 
    313333 
    314 6) /fullpathto/mytracproject/conf/trac.ini を修正します。 
     334 6. Modify `/fullpathto/mytracproject/conf/trac.ini` 
    315335 
    316336{{{ 
     
    321341}}} 
    322342 
    323 7) [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeed] を "lswsctrl restart" で再起動し、新しい Trac プロジェクトに以下の URL でアクセスします: 
     343 7. Restart !LiteSpeed, “lswsctrl restart”, and access your new Trac project at:  
    324344 
    325345{{{ 
     
    327347}}} 
    328348 
     349== Simple Nginx Configuration == 
     350 
     351 1. Nginx configuration snippet - confirmed to work on 0.6.32 
     352{{{ 
     353    server { 
     354        listen       10.9.8.7:443; 
     355        server_name  trac.example; 
     356 
     357        ssl                  on; 
     358        ssl_certificate      /etc/ssl/trac.example.crt; 
     359        ssl_certificate_key  /etc/ssl/trac.example.key; 
     360 
     361        ssl_session_timeout  5m; 
     362 
     363        ssl_protocols  SSLv2 SSLv3 TLSv1; 
     364        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; 
     365        ssl_prefer_server_ciphers   on; 
     366 
     367        # (Or ``^/some/prefix/(.*)``. 
     368        if ($uri ~ ^/(.*)) { 
     369             set $path_info /$1; 
     370        } 
     371 
     372        # You can copy this whole location to ``location [/some/prefix]/login`` 
     373        # and remove the auth entries below if you want Trac to enforce 
     374        # authorization where appropriate instead of needing to authenticate 
     375        # for accessing the whole site. 
     376        # (Or ``location /some/prefix``.) 
     377        location / { 
     378            auth_basic            "trac realm"; 
     379            auth_basic_user_file /home/trac/htpasswd; 
     380 
     381            # socket address 
     382            fastcgi_pass   unix:/home/trac/run/instance.sock; 
     383 
     384            # python - wsgi specific 
     385            fastcgi_param HTTPS on; 
     386 
     387            ## WSGI REQUIRED VARIABLES 
     388            # WSGI application name - trac instance prefix. 
     389            # (Or ``fastcgi_param  SCRIPT_NAME  /some/prefix``.) 
     390            fastcgi_param  SCRIPT_NAME        ""; 
     391            fastcgi_param  PATH_INFO          $path_info; 
     392 
     393            ## WSGI NEEDED VARIABLES - trac warns about them 
     394            fastcgi_param  REQUEST_METHOD     $request_method; 
     395            fastcgi_param  SERVER_NAME        $server_name; 
     396            fastcgi_param  SERVER_PORT        $server_port; 
     397            fastcgi_param  SERVER_PROTOCOL    $server_protocol; 
     398            fastcgi_param  QUERY_STRING     $query_string; 
     399 
     400            # for authentication to work 
     401            fastcgi_param  AUTH_USER          $remote_user; 
     402            fastcgi_param  REMOTE_USER        $remote_user; 
     403        } 
     404    } 
     405}}} 
     406 
     407 2. Modified trac.fcgi: 
     408 
     409{{{ 
     410#!/usr/bin/env python 
     411import os 
     412sockaddr = '/home/trac/run/instance.sock' 
     413os.environ['TRAC_ENV'] = '/home/trac/instance' 
     414 
     415try: 
     416     from trac.web.main import dispatch_request 
     417     import trac.web._fcgi 
     418 
     419     fcgiserv = trac.web._fcgi.WSGIServer(dispatch_request,  
     420          bindAddress = sockaddr, umask = 7) 
     421     fcgiserv.run() 
     422 
     423except SystemExit: 
     424    raise 
     425except Exception, e: 
     426    print 'Content-Type: text/plain\r\n\r\n', 
     427    print 'Oops...' 
     428    print 
     429    print 'Trac detected an internal error:' 
     430    print 
     431    print e 
     432    print 
     433    import traceback 
     434    import StringIO 
     435    tb = StringIO.StringIO() 
     436    traceback.print_exc(file=tb) 
     437    print tb.getvalue() 
     438 
     439}}} 
     440 
     441 3. reload nginx and launch trac.fcgi like that: 
     442 
     443{{{ 
     444trac@trac.example ~ $ ./trac-standalone-fcgi.py  
     445}}} 
     446 
     447The above assumes that: 
     448 * There is a user named 'trac' for running trac instances and keeping trac environments in its home directory. 
     449 * `/home/trac/instance` contains a trac environment 
     450 * `/home/trac/htpasswd` contains authentication information 
     451 * `/home/trac/run` is owned by the same group the nginx runs under 
     452  * and if your system is Linux the `/home/trac/run` has setgid bit set (`chmod g+s run`) 
     453  * and patch from ticket #T7239 is applied, or you'll have to fix the socket file permissions every time 
     454 
     455Unfortunately nginx does not support variable expansion in fastcgi_pass directive.  
     456Thus it is not possible to serve multiple trac instances from one server block.  
     457 
     458If you worry enough about security, run trac instances under separate users.  
     459 
     460Another way to run trac as a FCGI external application is offered in ticket #T6224 
     461 
    329462---- 
    330 See also TracCgi, TracModPython, TracInstall, TracGuide 
     463See also:  TracGuide, TracInstall, [wiki:TracModWSGI ModWSGI], [wiki:TracCgi CGI], [wiki:TracModPython ModPython], [trac:TracNginxRecipe TracNginxRecipe]