XPressME Integration Kit

Trac

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

差分発生行の前後
Ignore:
Timestamp:
Oct 30, 2008, 4:53:49 PM (15 years 前)
Author:
trac (IP: 127.0.0.1)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracFastCgi

    v1 v1  
     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 
     14Apache で利用可能な FastCGI モジュールは 2 種類あります: `mod_fastcgi` と  
     15`mod_fcgid` です。これ以降に書かれている `FastCgiIpcDir` と `FastCgiConfig` ディレクティブ 
     16は `mod_fastcgi` のディレクティブです; `DefaultInitEnv` は `mod_fcgid`  
     17のディレクティブです。 
     18 
     19`mod_fastcgi` では、 Apache の設定ファイルに以下の設定を追記します。 
     20ファイル: 
     21{{{ 
     22# Enable fastcgi for .fcgi files 
     23# (If you're using a distro package for mod_fcgi, something like 
     24# this is probably already present) 
     25<IfModule mod_fastcgi.c> 
     26   AddHandler fastcgi-script .fcgi 
     27   FastCgiIpcDir /var/lib/apache2/fastcgi  
     28</IfModule> 
     29LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so 
     30}}} 
     31デフォルトの設定に問題がなければ、 `FastCgiIpcDir` の設定は必須ではありません。 `LoadModule` の行は `IfModule` グループの後になければいけないことに注意して下さい。 
     32 
     33`ScriptAlias` を設定するもしくは似たオプションが TracCgi で説明されていますが、  
     34`trac.cgi` の代わりに `trac.fcgi` を呼びます。 
     35 
     36`TRAC_ENV` を以下のように設定することができます: 
     37{{{ 
     38FastCgiConfig -initial-env TRAC_ENV=/path/to/env/trac 
     39}}} 
     40 
     41もしくは複数の Trac プロジェクトを扱っているときは、このように設定します: 
     42{{{ 
     43FastCgiConfig -initial-env TRAC_ENV_PARENT_DIR=/parent/dir/of/projects 
     44}}} 
     45 
     46これらの設定は、 `mod_fcgid` では動きません。似ていますが  
     47`mod_fcgid` での部分的な解決策は以下の通りになります: 
     48{{{ 
     49DefaultInitEnv TRAC_ENV /path/to/env/trac/ 
     50}}} 
     51しかし、これは `Directory` や `Location` コンテキストで使用することができません。 
     52よって、複数のプロジェクトに対応するのは難しくなります。 
     53 
     54これらのモジュールの両方 (同様に [http://www.lighttpd.net/ lighttpd] と CGI も) で動かすよりよい方法は、  
     55`trac.fcgi` に以下の値を設定することです。  
     56Web サーバに環境変数を設定する必要がなくなります。例: 
     57{{{ 
     58import os 
     59os.environ['TRAC_ENV'] = "/path/to/projectenv" 
     60}}} 
     61or 
     62{{{ 
     63import os 
     64os.environ['TRAC_ENV_PARENT_DIR'] = "/path/to/project/parent/dir" 
     65}}} 
     66 
     67プロジェクトごとの `ScriptAliases` と `.fcgi` スクリプトを設定すれば、 
     68この方法を使用して複数のプロジェクトに対応することができます。  
     69`trac.fcgi` をコピーして、ファイル名を適切に変更し、上記のコードをそれぞれのスクリプトに追記します。 
     70 
     71この [https://coderanger.net/~coderanger/httpd/fcgi_example.conf fcgid 設定例] を見たところ、 !ScriptAlias ディレクティブでは末尾の / も含めて、このように設定する: 
     72{{{ 
     73ScriptAlias / /srv/tracsite/cgi-bin/trac.fcgi/ 
     74}}} 
     75 
     76== Simple Cherokee Configuration == 
     77 
     78Configuration wanted. 
     79 
     80== 単純な Lighttpd の設定 == #SimpleLighttpdConfiguration 
     81 
     82FastCGI フロントエンドは最初 [http://www.lighttpd.net/ lighttpd] のような、 Apache 以外の Web サーバのために開発されました。 
     83 
     84lighttpd はセキュアで高速で、規格に準拠したとても柔軟な Web サーバで、高いパフォーマンスの環境で最適化されます。 
     85他の Web サーバに比べて CPU や、メモリの占有率がとても少ないです。 
     86 
     87`trac.fcgi` を lighttpd で使用するためには、 lighttpd.conf に以下の行を追加します: 
     88{{{ 
     89fastcgi.server = ("/trac" => 
     90                   ("trac" => 
     91                     ("socket" => "/tmp/trac-fastcgi.sock", 
     92                      "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     93                      "check-local" => "disable", 
     94                      "bin-environment" => 
     95                        ("TRAC_ENV" => "/path/to/projenv") 
     96                     ) 
     97                   ) 
     98                 ) 
     99}}} 
     100 
     101動かしたい Trac のインスタンス毎に `fastcgi.server` のエントリを追加する必要があります。別の方法として、、上記の `TRAC_ENV` の代わりに `TRAC_ENV_PARENT_DIR` を使用でき、  
     102`lighttpd.conf` に設定する代わりに `trac.fcgi` ファイルに  
     103`bin-environment` (上記の Apache の設定 に書かれています) の2つのうちのどちらかを設定します。 
     104 
     105lighttpd で2つのプロジェクトを動かすには、 `lighttpd.conf` に以下の設定を追加します: 
     106{{{ 
     107fastcgi.server = ("/first" => 
     108                   ("first" => 
     109                    ("socket" => "/tmp/trac-fastcgi-first.sock", 
     110                     "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     111                     "check-local" => "disable", 
     112                     "bin-environment" => 
     113                       ("TRAC_ENV" => "/path/to/projenv-first") 
     114                    ) 
     115                  ), 
     116                  "/second" => 
     117                    ("second" => 
     118                    ("socket" => "/tmp/trac-fastcgi-second.sock", 
     119                     "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     120                     "check-local" => "disable", 
     121                     "bin-environment" => 
     122                       ("TRAC_ENV" => "/path/to/projenv-second") 
     123                    ) 
     124                  ) 
     125                ) 
     126}}} 
     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 と認証方法を選択して下さい: 
     139{{{ 
     140server.modules              = ( 
     141... 
     142  "mod_auth", 
     143... 
     144) 
     145 
     146auth.backend               = "htpasswd" 
     147 
     148# Separated password files for each project 
     149# See "Conditional Configuration" in 
     150# http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/configuration.txt 
     151 
     152$HTTP["url"] =~ "^/first/" { 
     153  auth.backend.htpasswd.userfile = "/path/to/projenv-first/htpasswd.htaccess" 
     154} 
     155$HTTP["url"] =~ "^/second/" { 
     156  auth.backend.htpasswd.userfile = "/path/to/projenv-second/htpasswd.htaccess" 
     157} 
     158 
     159# Enable auth on trac URLs, see 
     160# http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/authentication.txt 
     161 
     162auth.require = ("/first/login" => 
     163                ("method"  => "basic", 
     164                 "realm"   => "First project", 
     165                 "require" => "valid-user" 
     166                ), 
     167                "/second/login" => 
     168                ("method"  => "basic", 
     169                 "realm"   => "Second project", 
     170                 "require" => "valid-user" 
     171                ) 
     172               ) 
     173 
     174 
     175}}} 
     176パスワードファイルがない場合、 lighttpd (確認したバージョンは 1.4.3) が停止するので注意して下さい。 
     177 
     178バージョン 1.3.16 以前では lighttpd は 'valid-user' をサポートしていないので注意してください。 
     179 
     180条件付の設定は静的リソースをマッピングするときに便利です。例として FastCGI を経由せずに直接イメージファイルや CSS を参照するときなどです。: 
     181{{{ 
     182# Aliasing functionality is needed 
     183server.modules += ("mod_alias") 
     184 
     185# Setup an alias for the static resources 
     186alias.url = ("/trac/chrome/common" => "/usr/share/trac/htdocs") 
     187 
     188# Use negative lookahead, matching all requests that ask for any resource under /trac, EXCEPT in 
     189# /trac/chrome/common, and use FastCGI for those 
     190$HTTP["url"] =~ "^/trac(?!/chrome/common)" { 
     191# Even if you have other fastcgi.server declarations for applications other than Trac, do NOT use += here 
     192fastcgi.server = ("/trac" => 
     193                   ("trac" => 
     194                     ("socket" => "/tmp/trac-fastcgi.sock", 
     195                      "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     196                      "check-local" => "disable", 
     197                      "bin-environment" => 
     198                        ("TRAC_ENV" => "/path/to/projenv") 
     199                     ) 
     200                   ) 
     201                 ) 
     202} 
     203}}} 
     204複数のプロジェクトのそれぞれにエイリアスを作れば、複数のプロジェクトを動かすのは技術的には簡単です。 fastcgi.server を条件ブロックの中で宣言しラッピングします。 
     205複数のプロジェクトをハンドルするもう一つの方法があります。 TRAC_ENV_PARENT_DIR を TRAC_ENV の代わりに使用し、グローバルの認証機構を使用します。サンプルを見てみましょう: 
     206{{{ 
     207#  This is for handling multiple projects 
     208  alias.url       = ( "/trac/" => "/path/to/trac/htdocs/" ) 
     209 
     210  fastcgi.server += ("/projects"  => 
     211                      ("trac" => 
     212                        ( 
     213                          "socket" => "/tmp/trac.sock", 
     214                          "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     215                          "check-local" => "disable", 
     216                          "bin-environment" => 
     217                            ("TRAC_ENV_PARENT_DIR" => "/path/to/parent/dir/of/projects/" ) 
     218                        ) 
     219                      ) 
     220                    ) 
     221#And here starts the global auth configuration 
     222  auth.backend = "htpasswd" 
     223  auth.backend.htpasswd.userfile = "/path/to/unique/htpassword/file/trac.htpasswd" 
     224  $HTTP["url"] =~ "^/projects/.*/login$" { 
     225    auth.require = ("/" => 
     226                     ( 
     227                       "method"  => "basic", 
     228                       "realm"   => "trac", 
     229                       "require" => "valid-user" 
     230                     ) 
     231                   ) 
     232  } 
     233}}} 
     234 
     235lighttpd では環境変数の LC_TIME を上書きして、日付/時間のフォーマットを変更することも出来ます。 
     236{{{ 
     237fastcgi.server = ("/trac" => 
     238                   ("trac" => 
     239                     ("socket" => "/tmp/trac-fastcgi.sock", 
     240                      "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     241                      "check-local" => "disable", 
     242                      "bin-environment" => 
     243                        ("TRAC_ENV" => "/path/to/projenv", 
     244                        "LC_TIME" => "ru_RU") 
     245                     ) 
     246                   ) 
     247                 ) 
     248}}} 
     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 
     253trac-0.9 を使用している場合、[http://lists.edgewall.com/archive/trac/2005-November/005311.html 些細なバグ] について読んでください。 
     254 
     255lighttpd を再起動し、ブラウザに `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 
     264FastCGI フロントエンドは最初 [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 
     2701) 最初に Trac プロジェクトをインストールして動作することを確認して下さい。最初のインストールでは、 "tracd" を使用します。 
     271 
     2722) このセットアップでは仮想ホストを作成します。以下、この仮想ホストのことを !TracVhost と呼びます。このチュートリアルで、先ほど作ったプロジェクトが以下の URL 経由でアクセスできると仮定します: 
     273 
     274{{{ 
     275http://yourdomain.com/trac/ 
     276}}} 
     277 
     2783) "!TracVhost → External AApps" タブへ移動し、新しい "External Application" を作成します。 
     279 
     280{{{ 
     281Name: MyTracFCGI         
     282Address: uds://tmp/lshttpd/mytracfcgi.sock 
     283Max Connections: 10 
     284Environment: TRAC_ENV=/fullpathto/mytracproject/ <--- path to root folder of trac project 
     285Initial Request Timeout (secs): 30 
     286Retry Timeout (secs): 0 
     287Persistent Connection   Yes 
     288Connection Keepalive Timeout: 30 
     289Response Bufferring: No  
     290Auto Start: Yes 
     291Command: /usr/share/trac/cgi-bin/trac.fcgi  <--- path to trac.fcgi 
     292Back Log: 50 
     293Instances: 10 
     294}}} 
     295 
     2964) (非必須) "!TracVhost → Security" タブへ移動し、新しいセキュリティ "Realm" を作成することができます。 
     297 
     298{{{ 
     299DB Type: Password File 
     300Realm Name: MyTracUserDB               <--- any name you wish and referenced later 
     301User DB Location: /fullpathto/htpasswd <--- path to your htpasswd file 
     302}}} 
     303 
     304もし、 htpasswd ファイルを持っていない、もしくは作り方を知らない場合は、 http://sherylcanter.com/encrypt.php にアクセスし、ユーザ名:パスワード の一対を生成して下さい。 
     305 
     3065) "!PythonVhost → Contexts" へ移動し、新しい "FCGI Context" を作成します。 
     307 
     308{{{ 
     309URI: /trac/                              <--- URI path to bind to python fcgi app we created     
     310Fast CGI App: [VHost Level] MyTractFCGI  <--- select the trac fcgi extapp we just created 
     311Realm: TracUserDB                        <--- only if (4) is set. select realm created in (4) 
     312}}} 
     313 
     3146) /fullpathto/mytracproject/conf/trac.ini を修正します。 
     315 
     316{{{ 
     317#find/set base_rul, url, and link variables 
     318base_url = http://yourdomain.com/trac/ <--- base url to generate correct links to 
     319url = http://yourdomain.com/trac/      <--- link of project 
     320link = http://yourdomain.com/trac/     <--- link of graphic logo 
     321}}} 
     322 
     3237) [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeed] を "lswsctrl restart" で再起動し、新しい Trac プロジェクトに以下の URL でアクセスします: 
     324 
     325{{{ 
     326http://yourdomain.com/trac/ 
     327}}} 
     328 
     329---- 
     330See also TracCgi, TracModPython, TracInstall, TracGuide