close Warning: Can't synchronize with repository "(default)" (/var/svn/mioproject does not appear to be a Subversion repository.). Look in the Trac log for more information.

Changes between Version 2 and Version 3 of TracFastCgi


Ignore:
Timestamp:
Jul 30, 2013, 8:39:06 PM (12 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracFastCgi

    v2 v3  
    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 '''Note for Windows:''' Trac's FCGI 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, your choice may be [trac:TracOnWindowsIisAjp AJP].
    6 '''Windows 向けの Note:''' Trac の FCGI は Windows では使用できません。 `_fcgi.py` が必要とする `Socket.fromfd` が Windows では実装されていないためです。 IIS を使用しているのであれば、 [http://trac.edgewall.org/wiki/TracOnWindowsIisAjp AJP] を使うこともできます。 (訳注: Apache でも mod_proxy_ajp 経由で ajp を使用できます。)
    7 
    8 == 単純な Apache の設定 == #SimpleApacheconfiguration
    9 
    10 Apache で利用可能な FastCGI モジュールは 2 種類あります: `mod_fastcgi` と
    11 `mod_fcgid` です。これ以降に書かれている `FastCgiIpcDir` と `FastCgiConfig` ディレクティブ
    12 は `mod_fastcgi` のディレクティブです; `DefaultInitEnv` は `mod_fcgid`
    13 のディレクティブです。
    14 
    15 `mod_fastcgi` では、 Apache の設定ファイルに以下の設定を追記します。
    16 ファイル:
     1[[PageOutline]]
     2
     3= Trac with FastCGI =
     4
     5[http://www.fastcgi.com/ FastCGI] interface allows Trac to remain resident much like with [wiki:TracModPython mod_python] or [wiki:TracModWSGI mod_wsgi]. It is faster than external CGI interfaces which must start a new process for each request.  Additionally, it is supported by much wider variety of web servers.
     6
     7Note that unlike mod_python, FastCGI supports [http://httpd.apache.org/docs/suexec.html Apache SuEXEC], i.e. run with different permissions than web server running with (`mod_wsgi` supports the `WSGIDaemonProcess` with user / group parameters to achieve the same effect).
     8
     9'''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]/[trac:TracOnWindowsIisAjp ISAPI].
     10
     11[[PageOutline(2-3,Overview,inline)]]
     12
     13
     14== Simple Apache configuration ==
     15
     16There are two FastCGI modules commonly available for Apache: `mod_fastcgi` and
     17`mod_fcgid` (preferred). The latter is more up-to-date.
     18
     19The following sections focus on the FCGI specific setup, see also [wiki:TracModWSGI#ConfiguringAuthentication] for configuring the authentication in Apache.
     20
     21Regardless of which cgi module is used, be sure the web server has executable permissions on the cgi-bin folder. While FastCGI will throw specific permissions errors, mod_fcgid will throw an ambiguous error if this has not been done. (Connection reset by peer: mod_fcgid: error reading data from FastCGI server)
     22
     23=== Set up with `mod_fastcgi` ===
     24`mod_fastcgi` uses `FastCgiIpcDir` and `FastCgiConfig` directives that should be added to an appropriate Apache configuration file:
    1725{{{
    1826# Enable fastcgi for .fcgi files
     
    2533LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
    2634}}}
    27 デフォルトの設定に問題がなければ、 `FastCgiIpcDir` の設定は必須ではありません。 `LoadModule` の行は `IfModule` グループの後になければいけないことに注意して下さい。
    28 
    29 `ScriptAlias` を設定するもしくは似たオプションが TracCgi で説明されていますが、
    30 `trac.cgi` の代わりに `trac.fcgi` を呼びます。
    31 
    32 `TRAC_ENV` を以下のように設定することができます:
     35Setting `FastCgiIpcDir` is optional if the default is suitable. Note that the `LoadModule` line must be after the `IfModule` group.
     36
     37Configure `ScriptAlias` or similar options as described in TracCgi, but
     38calling `trac.fcgi` instead of `trac.cgi`.
     39
     40Add the following to the Apache configuration file (below the `FastCgiIpcDir` line) if you intend to set up the `TRAC_ENV` as an overall default:
    3341{{{
    3442FastCgiConfig -initial-env TRAC_ENV=/path/to/env/trac
    3543}}}
    3644
    37 もしくは複数の Trac プロジェクトを扱っているときは、このように設定します:
     45Alternatively, you can serve multiple Trac projects in a directory by adding this:
    3846{{{
    3947FastCgiConfig -initial-env TRAC_ENV_PARENT_DIR=/parent/dir/of/projects
    4048}}}
    4149
    42 これらの設定は、 `mod_fcgid` では動きません。似ていますが
    43 `mod_fcgid` での部分的な解決策は以下の通りになります:
     50=== Set up with `mod_fcgid` ===
     51Configure `ScriptAlias` (see TracCgi for details), but call `trac.fcgi`
     52instead of `trac.cgi`. Note that slash at the end - it is important.
     53{{{
     54ScriptAlias /trac /path/to/www/trac/cgi-bin/trac.fcgi/
     55}}}
     56
     57To set up Trac environment for `mod_fcgid` it is necessary to use
     58`DefaultInitEnv` directive. It cannot be used in `Directory` or
     59`Location` context, so if you need to support multiple projects, try
     60alternative environment setup below.
     61
    4462{{{
    4563DefaultInitEnv TRAC_ENV /path/to/env/trac/
    4664}}}
    47 しかし、これは `Directory` や `Location` コンテキストで使用することができません。
    48 よって、複数のプロジェクトに対応するのは難しくなります。
    49 
    50 これらのモジュールの両方 (同様に [http://www.lighttpd.net/ lighttpd] と CGI も) で動かすよりよい方法は、
    51 `trac.fcgi` に以下の値を設定することです。
    52 Web サーバに環境変数を設定する必要がなくなります。例:
     65
     66=== alternative environment setup ===
     67A better method to specify path to Trac environment is to embed the path
     68into `trac.fcgi` script itself. That doesn't require configuration of server
     69environment variables, works for both FastCgi modules
     70(and for [http://www.lighttpd.net/ lighttpd] and CGI as well):
    5371{{{
    5472import os
     
    6179}}}
    6280
    63 プロジェクトごとの `ScriptAliases` と `.fcgi` スクリプトを設定すれば、
    64 この方法を使用して複数のプロジェクトに対応することができます。
    65 `trac.fcgi` をコピーして、ファイル名を適切に変更し、上記のコードをそれぞれのスクリプトに追記します。
    66 
    67 この [https://coderanger.net/~coderanger/httpd/fcgi_example.conf fcgid 設定例] を見たところ、 !ScriptAlias ディレクティブでは末尾の / も含めて、このように設定する:
     81With this method different projects can be supported by using different
     82`.fcgi` scripts with different `ScriptAliases`.
     83
     84See [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:
    6885{{{
    6986ScriptAlias / /srv/tracsite/cgi-bin/trac.fcgi/
     
    87104
    88105After 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.
    89 The 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/''
    90 
    91 == 単純な Lighttpd の設定 == #SimpleLighttpdConfiguration
    92 
    93 FastCGI フロントエンドは最初 [http://www.lighttpd.net/ lighttpd] のような、 Apache 以外の Web サーバのために開発されました。
    94 
    95 lighttpd はセキュアで高速で、規格に準拠したとても柔軟な Web サーバで、高いパフォーマンスの環境で最適化されます。
    96 他の Web サーバに比べて CPU や、メモリの占有率がとても少ないです。
    97 
    98 `trac.fcgi` (0.11 より前) もしくは fcgi_frontend.py (0.11) を lighttpd で使用するためには、 lighttpd.conf に以下の行を追加します:
    99 {{{
    100 #var.fcgi_binary="/path/to/fcgi_frontend.py" # 0.11 if installed with easy_setup, it is inside the egg directory
     106The second rule will be there to serve the few static files needed to correctly display the Trac interface. Create it as ''Directory rule'' for ''/common'' and just set it to the ''Static files'' handler and with a ''Document root'' that points to the appropriate files: ''$TRAC_LOCAL/htdocs/'' (where $TRAC_LOCAL is a directory defined by the user or the system administrator to place local trac resources).
     107
     108Note:\\
     109If the tracd process fails to start up, and cherokee displays a 503 error page, you might be missing the [http://trac.saddi.com/flup python-flup] package.\\
     110Python-flup is a dependency which provides trac with SCGI capability. You can install it on debian based systems with:
     111{{{
     112sudo apt-get install python-flup
     113}}}
     114
     115
     116== Simple Lighttpd Configuration ==
     117
     118The FastCGI front-end was developed primarily for use with alternative webservers, such as [http://www.lighttpd.net/ lighttpd].
     119
     120lighttpd is a secure, fast, compliant and very flexible web-server that has been optimized for high-performance
     121environments.  It has a very low memory footprint compared to other web servers and takes care of CPU load.
     122
     123For using `trac.fcgi`(prior to 0.11) / fcgi_frontend.py (0.11) with lighttpd add the following to your 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
    101126var.fcgi_binary="/path/to/cgi-bin/trac.fcgi" # 0.10 name of prior fcgi executable
    102127fastcgi.server = ("/trac" =>
     
    113138}}}
    114139
    115 動かしたい Trac のインスタンス毎に `fastcgi.server` のエントリを追加する必要があります。別の方法として、、上記の `TRAC_ENV` の代わりに `TRAC_ENV_PARENT_DIR` を使用でき、
    116 `lighttpd.conf` に設定する代わりに `trac.fcgi` ファイルに
    117 `bin-environment` (上記の Apache の設定 に書かれています) の2つのうちのどちらかを設定します。
    118 
    119 lighttpd で2つのプロジェクトを動かすには、 `lighttpd.conf` に以下の設定を追加します:
     140Note 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,
     141and you may set one of the two in `trac.fcgi` instead of in `lighttpd.conf`
     142using `bin-environment` (as in the section above on Apache configuration).
     143
     144Note 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 [trac:#2418]). This is fixed in lighttpd 1.5, and under lighttpd 1.4.23 or later the workaround is to add `"fix-root-scriptname" => "enable"` as a parameter of fastcgi.server.
     145
     146For using two projects with lighttpd add the following to your `lighttpd.conf`:
    120147{{{
    121148fastcgi.server = ("/first" =>
     
    139166                )
    140167}}}
    141 各フィールドの値が異なることに注意して下さい。もし `.fcgi` スクリプトに
    142 環境変数を設定するほうが好ましい場合は、 `trac.fcgi` をコピー/名前変更をして下さい。例として、
    143 `first.fcgi` と `second.fcgi` が上記の設定では参照されるようにします。
    144 上記の設定で、両方のプロジェクトが 同じ `trac.fcgi` スクリプトで起動していても、
    145 異なるプロセスになることに注意して下さい。
     168Note that field values are different.  If you prefer setting the environment
     169variables in the `.fcgi` scripts, then copy/rename `trac.fcgi`, e.g., to
     170`first.fcgi` and `second.fcgi`, and reference them in the above settings.
     171Note that the above will result in different processes in any event, even
     172if both are running from the same `trac.fcgi` script.
     173
    146174{{{
    147175#!div class=important
    148 '''Note''' server.modules をロードする順番はとても重要です。 mod_auth が mod_fastcgi より '''先に''' ロードされる設定になっていない場合、サーバはユーザの認証に失敗します。
    149 }}}
    150 認証のために lighttpd.conf の 'server.modules' 中で mod_auth を有効にして、 auth.backend と認証方法を選択して下さい:
     176'''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.
     177}}}
     178
     179For authentication you should enable mod_auth in lighttpd.conf 'server.modules', select auth.backend and auth rules:
    151180{{{
    152181server.modules              = (
     
    186215
    187216}}}
    188 パスワードファイルがない場合、 lighttpd (確認したバージョンは 1.4.3) が停止するので注意して下さい。
    189 
    190 バージョン 1.3.16 以前では lighttpd は 'valid-user' をサポートしていないので注意してください。
    191 
    192 条件付の設定は静的リソースをマッピングするときに便利です。例として FastCGI を経由せずに直接イメージファイルや CSS を参照するときなどです。:
     217Note that lighttpd (I use version 1.4.3) stopped if password file doesn't exist.
     218
     219Note that lighttpd doesn't support 'valid-user' in versions prior to 1.3.16.
     220
     221Conditional configuration is also useful for mapping static resources, i.e. serving out images and CSS directly instead of through FastCGI:
    193222{{{
    194223# Aliasing functionality is needed
    195224server.modules += ("mod_alias")
    196225
    197 # Setup an alias for the static resources
     226# Set up an alias for the static resources
    198227alias.url = ("/trac/chrome/common" => "/usr/share/trac/htdocs")
    199228
     
    214243}
    215244}}}
    216 複数のプロジェクトのそれぞれにエイリアスを作れば、複数のプロジェクトを動かすのは技術的には簡単です。 fastcgi.server を条件ブロックの中で宣言しラッピングします。
    217 複数のプロジェクトをハンドルするもう一つの方法があります。 TRAC_ENV_PARENT_DIR を TRAC_ENV の代わりに使用し、グローバルの認証機構を使用します。サンプルを見てみましょう:
     245The 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.
     246Also 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:
    218247{{{
    219248#  This is for handling multiple projects
     
    245274}}}
    246275
    247 lighttpd では環境変数の LC_TIME を上書きして、日付/時間のフォーマットを変更することも出来ます。
     276Changing date/time format also supported by lighttpd over environment variable LC_TIME
    248277{{{
    249278fastcgi.server = ("/trac" =>
     
    259288                 )
    260289}}}
    261 使用言語指定の詳細については [http://trac.lighttpd.net/trac/wiki/TracFaq TracFaq] の 2.13 の質問を参照して下さい。
    262 
    263 その他重要な情報、例えば、 [http://trac.lighttpd.net/trac/wiki/TracInstall lighttpd の TracInstall] や、 [wiki:TracCgi#静的なリソースをマッピングする TracCgi] などは fast-cgi 固有ではありませんが、インストールの詳細をつかむのに有用でしょう。
    264 
    265 trac-0.9 を使用している場合、[http://lists.edgewall.com/archive/trac/2005-November/005311.html 些細なバグ] について読んでください。
    266 
    267 lighttpd を再起動し、ブラウザに `http://yourhost.example.org/trac` を入力して、 Trac にアクセスして下さい。
    268 
    269 制限された権限で lighttpd を起動するにあたって気をつけること:
    270 
    271   もし、 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 を起動するユーザに適宜読み替えてください。)
    272 
    273 
    274 == 簡単な !LiteSpeeed の設定 == #SimpleLiteSpeedConfiguration
    275 
    276 FastCGI フロントエンドは [http://www.litespeedtech.com/ LiteSpeed] のような、 Apache 以外の Web サーバのために開発されました。
    277 
    278 !LiteSpeed Web サーバはイベント駆動、非同期型であり、Apache に代わるものとしてセキュアで拡張可能になるようにゼロからデザインされています。そして、最低限のリソースで操作できます。 !LiteSpeed は Apache の設定ファイルから直接操作でき、ビジネスに不可欠な環境をターゲットにしています。
    279 
    280 セットアップ
    281 
    282 1) 最初に Trac プロジェクトをインストールして動作することを確認して下さい。最初のインストールでは、 "tracd" を使用します。
    283 
    284 2) このセットアップでは仮想ホストを作成します。以下、この仮想ホストのことを !TracVhost と呼びます。このチュートリアルで、先ほど作ったプロジェクトが以下の URL 経由でアクセスできると仮定します:
     290For details about languages specification see [trac:TracFaq TracFaq] question 2.13.
     291
     292Other important information like the [wiki:TracInstall#MappingStaticResources mapping static resources advices] are useful for non-fastcgi specific installation aspects.
     293]
     294
     295Relaunch lighttpd, and browse to `http://yourhost.example.org/trac` to access Trac.
     296
     297Note about running lighttpd with reduced permissions:
     298
     299If 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.
     300
     301
     302== Simple !LiteSpeed Configuration ==
     303
     304The FastCGI front-end was developed primarily for use with alternative webservers, such as [http://www.litespeedtech.com/ LiteSpeed].
     305
     306!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.
     307
     308 1. Please make sure you have first have a working install of a Trac project. Test install with “tracd” first.
     309
     310 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:
    285311
    286312{{{
     
    288314}}}
    289315
    290 3) "!TracVhost → External AApps" タブへ移動し、新しい "External Application" を作成します。
     316 3. Go “!TracVhost → External Apps” tab and create a new “External Application”.
    291317
    292318{{{
     
    306332}}}
    307333
    308 4) (非必須) "!TracVhost → Security" タブへ移動し、新しいセキュリティ "Realm" を作成することができます。
     334 4. Optional. If you need to use htpasswd based authentication. Go to “!TracVhost → Security” tab and create a new security “Realm”.
    309335
    310336{{{
     
    314340}}}
    315341
    316 もし、 htpasswd ファイルを持っていない、もしくは作り方を知らない場合は、 http://sherylcanter.com/encrypt.php にアクセスし、ユーザ名:パスワード の一対を生成して下さい。
    317 
    318 5) "!PythonVhost → Contexts" へ移動し、新しい "FCGI Context" を作成します。
     342If 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.
     343
     344 5. Go to “!PythonVhost → Contexts” and create a new “FCGI Context”.
    319345
    320346{{{
     
    324350}}}
    325351
    326 6) /fullpathto/mytracproject/conf/trac.ini を修正します。
     352 6. Modify `/fullpathto/mytracproject/conf/trac.ini`
    327353
    328354{{{
     
    333359}}}
    334360
    335 7) !LiteSpeed を "lswsctrl restart" で再起動し、新しい Trac プロジェクトに以下の URL でアクセスします:
    336 
     361 7. Restart !LiteSpeed, “lswsctrl restart”, and access your new Trac project at:
    337362
    338363{{{
     
    340365}}}
    341366
    342 === Simple Nginx Configuration ===
    343 
    344 1) Nginx configuration snippet - confirmed to work on 0.6.32
     367
     368== Simple Nginx Configuration ==
     369
     370Nginx is able to communicate with FastCGI processes, but can not spawn them. So you need to start FastCGI server for Trac separately.
     371
     372 1. Nginx configuration with basic authentication handled by Nginx - confirmed to work on 0.6.32
    345373{{{
    346374    server {
     
    361389        if ($uri ~ ^/(.*)) {
    362390             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/;
    363396        }
    364397
     
    389422            fastcgi_param  SERVER_PORT        $server_port;
    390423            fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    391 
    392             # for authentication to work
     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
    393428            fastcgi_param  AUTH_USER          $remote_user;
    394429            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;
    395437        }
    396438    }
    397439}}}
    398440
    399 2) Modified trac.fcgi:
     441 2. Modified trac.fcgi:
    400442
    401443{{{
     
    431473}}}
    432474
    433 3) reload nginx and launch trac.fcgi like that:
     475 3. reload nginx and launch trac.fcgi like that:
    434476
    435477{{{
     
    439481The above assumes that:
    440482 * There is a user named 'trac' for running trac instances and keeping trac environments in its home directory.
    441  * /home/trac/instance contains a trac environment
    442  * /home/trac/htpasswd contains authentication information
    443  * /home/trac/run is owned by the same group the nginx runs under
    444   * and if your system is Linux the /home/trac/run has setgid bit set (chmod g+s run)
     483 * `/home/trac/instance` contains a trac environment
     484 * `/home/trac/htpasswd` contains authentication information
     485 * `/home/trac/run` is owned by the same group the nginx runs under
     486  * and if your system is Linux the `/home/trac/run` has setgid bit set (`chmod g+s run`)
    445487  * and patch from ticket #T7239 is applied, or you'll have to fix the socket file permissions every time
    446488
     
    453495
    454496----
    455 See also:  TracGuide, TracInstall, [wiki:TracModWSGI ModWSGI], [wiki:TracCgi CGI], [wiki:TracModPython ModPython], [http://trac.edgewall.org/wiki/TracNginxRecipe TracNginxRecipe]
     497See also:  TracGuide, TracInstall, [wiki:TracModWSGI ModWSGI], [wiki:TracCgi CGI], [wiki:TracModPython ModPython], [trac:TracNginxRecipe TracNginxRecipe]