Changes between Version 2 and Version 3 of TracFastCgi


Ignore:
Timestamp:
2009/12/25 16:21:56 (14 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracFastCgi

    v2 v3  
    1 = Trac を FastCGI で使用する = 
     1= Trac を FastCGI で使用する = #TracwithFastCGI 
    22 
    33バージョン 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 サーバにサポートされています。 
    44 
    5 == 単純な Apache の設定 == 
     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 
    69 
    710Apache で利用可能な FastCGI モジュールは 2 種類あります: `mod_fastcgi` と  
    8 `mod_fcgid` です。 これ以降に書かれている `FastCgiIpcDir` と `FastCgiConfig` ディレクティブ 
    9 は `mod_fastcgi` のディレクティブです; `DefaultInitEnv` は `mod_fgcid`  
     11`mod_fcgid` です。これ以降に書かれている `FastCgiIpcDir` と `FastCgiConfig` ディレクティブ 
     12は `mod_fastcgi` のディレクティブです; `DefaultInitEnv` は `mod_fcgid`  
    1013のディレクティブです。 
    1114 
     
    6265`trac.fcgi` をコピーして、ファイル名を適切に変更し、上記のコードをそれぞれのスクリプトに追記します。 
    6366 
    64 == 単純な Lighttpd の設定 == 
     67この [https://coderanger.net/~coderanger/httpd/fcgi_example.conf fcgid 設定例] を見たところ、 !ScriptAlias ディレクティブでは末尾の / も含めて、このように設定する: 
     68{{{ 
     69ScriptAlias / /srv/tracsite/cgi-bin/trac.fcgi/ 
     70}}} 
     71 
     72== Simple Cherokee Configuration == 
     73 
     74The configuration on Cherokee's side is quite simple. You will only need to know that you can spawn Trac as an SCGI process. 
     75You can either start it manually, or better yet, automatically by letting Cherokee spawn the server whenever it is down. 
     76First set up an information source in cherokee-admin with a local interpreter. 
     77 
     78{{{ 
     79Host: 
     80localhost:4433 
     81 
     82Interpreter: 
     83/usr/bin/tracd —single-env —daemonize —protocol=scgi —hostname=localhost —port=4433 /path/to/project/ 
     84}}} 
     85 
     86If 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''. 
     87 
     88After 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. 
     89The 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 
    6592 
    6693FastCGI フロントエンドは最初 [http://www.lighttpd.net/ lighttpd] のような、 Apache 以外の Web サーバのために開発されました。 
     
    6996他の Web サーバに比べて CPU や、メモリの占有率がとても少ないです。 
    7097 
    71 `trac.fcgi` を lighttpd で使用するためには、 lighttpd.conf に以下の行を追加します: 
    72 {{{ 
     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 
     101var.fcgi_binary="/path/to/cgi-bin/trac.fcgi" # 0.10 name of prior fcgi executable 
    73102fastcgi.server = ("/trac" => 
     103    
    74104                   ("trac" => 
    75105                     ("socket" => "/tmp/trac-fastcgi.sock", 
    76                       "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     106                      "bin-path" => fcgi_binary, 
    77107                      "check-local" => "disable", 
    78108                      "bin-environment" => 
     
    92122                   ("first" => 
    93123                    ("socket" => "/tmp/trac-fastcgi-first.sock", 
    94                      "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     124                     "bin-path" => fcgi_binary, 
    95125                     "check-local" => "disable", 
    96126                     "bin-environment" => 
     
    101131                    ("second" => 
    102132                    ("socket" => "/tmp/trac-fastcgi-second.sock", 
    103                      "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     133                     "bin-path" => fcgi_binary, 
    104134                     "check-local" => "disable", 
    105135                     "bin-environment" => 
     
    110140}}} 
    111141各フィールドの値が異なることに注意して下さい。もし `.fcgi` スクリプトに 
    112 環境変数を設定するほうが好ましい場合は、 `trac.fcgi` をコピー / 名前変更をして下さい。例として、 
     142環境変数を設定するほうが好ましい場合は、 `trac.fcgi` をコピー/名前変更をして下さい。例として、 
    113143`first.fcgi` と `second.fcgi` が上記の設定では参照されるようにします。 
    114144上記の設定で、両方のプロジェクトが 同じ `trac.fcgi` スクリプトで起動していても、 
    115145異なるプロセスになることに注意して下さい。 
    116146{{{ 
    117 #!html 
    118 <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> ロードされる設定になっていない場合、サーバはユーザの認証に失敗します。 
    120 </p> 
     147#!div class=important 
     148'''Note''' server.modules をロードする順番はとても重要です。 mod_auth が mod_fastcgi より '''先に''' ロードされる設定になっていない場合、サーバはユーザの認証に失敗します。 
    121149}}} 
    122150認証のために lighttpd.conf の 'server.modules' 中で mod_auth を有効にして、 auth.backend と認証方法を選択して下さい: 
     
    177205                   ("trac" => 
    178206                     ("socket" => "/tmp/trac-fastcgi.sock", 
    179                       "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     207                      "bin-path" => fcgi_binary, 
    180208                      "check-local" => "disable", 
    181209                      "bin-environment" => 
     
    196224                        ( 
    197225                          "socket" => "/tmp/trac.sock", 
    198                           "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     226                          "bin-path" => fcgi_binary, 
    199227                          "check-local" => "disable", 
    200228                          "bin-environment" => 
     
    222250                   ("trac" => 
    223251                     ("socket" => "/tmp/trac-fastcgi.sock", 
    224                       "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     252                      "bin-path" => fcgi_binary, 
    225253                      "check-local" => "disable", 
    226254                      "bin-environment" => 
     
    244272 
    245273 
    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 の設定ファイルから直接操作でき、ビジネスに不可欠な環境をターゲットにしています。 
     274== 簡単な !LiteSpeeed の設定 == #SimpleLiteSpeedConfiguration 
     275 
     276FastCGI フロントエンドは [http://www.litespeedtech.com/ LiteSpeed] のような、 Apache 以外の Web サーバのために開発されました。 
     277 
     278!LiteSpeed Web サーバはイベント駆動、非同期型であり、Apache に代わるものとしてセキュアで拡張可能になるようにゼロからデザインされています。そして、最低限のリソースで操作できます。 !LiteSpeed は Apache の設定ファイルから直接操作でき、ビジネスに不可欠な環境をターゲットにしています。 
    251279 
    252280セットアップ 
     
    293321URI: /trac/                              <--- URI path to bind to python fcgi app we created     
    294322Fast 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) 
     323Realm: TracUserDB                        <--- only if (4) is set. select realm created in (4) 
    296324}}} 
    297325 
     
    305333}}} 
    306334 
    307 7) [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeed] を "lswsctrl restart" で再起動し、新しい Trac プロジェクトに以下の URL でアクセスします: 
     3357) !LiteSpeed を "lswsctrl restart" で再起動し、新しい Trac プロジェクトに以下の URL でアクセスします: 
     336 
    308337 
    309338{{{ 
     
    311340}}} 
    312341 
     342=== Simple Nginx Configuration === 
     343 
     3441) Nginx configuration snippet - confirmed to work on 0.6.32 
     345{{{ 
     346    server { 
     347        listen       10.9.8.7:443; 
     348        server_name  trac.example; 
     349 
     350        ssl                  on; 
     351        ssl_certificate      /etc/ssl/trac.example.crt; 
     352        ssl_certificate_key  /etc/ssl/trac.example.key; 
     353 
     354        ssl_session_timeout  5m; 
     355 
     356        ssl_protocols  SSLv2 SSLv3 TLSv1; 
     357        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; 
     358        ssl_prefer_server_ciphers   on; 
     359 
     360        # (Or ``^/some/prefix/(.*)``. 
     361        if ($uri ~ ^/(.*)) { 
     362             set $path_info /$1; 
     363        } 
     364 
     365        # You can copy this whole location to ``location [/some/prefix]/login`` 
     366        # and remove the auth entries below if you want Trac to enforce 
     367        # authorization where appropriate instead of needing to authenticate 
     368        # for accessing the whole site. 
     369        # (Or ``location /some/prefix``.) 
     370        location / { 
     371            auth_basic            "trac realm"; 
     372            auth_basic_user_file /home/trac/htpasswd; 
     373 
     374            # socket address 
     375            fastcgi_pass   unix:/home/trac/run/instance.sock; 
     376 
     377            # python - wsgi specific 
     378            fastcgi_param HTTPS on; 
     379 
     380            ## WSGI REQUIRED VARIABLES 
     381            # WSGI application name - trac instance prefix. 
     382            # (Or ``fastcgi_param  SCRIPT_NAME  /some/prefix``.) 
     383            fastcgi_param  SCRIPT_NAME        ""; 
     384            fastcgi_param  PATH_INFO          $path_info; 
     385 
     386            ## WSGI NEEDED VARIABLES - trac warns about them 
     387            fastcgi_param  REQUEST_METHOD     $request_method; 
     388            fastcgi_param  SERVER_NAME        $server_name; 
     389            fastcgi_param  SERVER_PORT        $server_port; 
     390            fastcgi_param  SERVER_PROTOCOL    $server_protocol; 
     391 
     392            # for authentication to work 
     393            fastcgi_param  AUTH_USER          $remote_user; 
     394            fastcgi_param  REMOTE_USER        $remote_user; 
     395        } 
     396    } 
     397}}} 
     398 
     3992) Modified trac.fcgi: 
     400 
     401{{{ 
     402#!/usr/bin/env python 
     403import os 
     404sockaddr = '/home/trac/run/instance.sock' 
     405os.environ['TRAC_ENV'] = '/home/trac/instance' 
     406 
     407try: 
     408     from trac.web.main import dispatch_request 
     409     import trac.web._fcgi 
     410 
     411     fcgiserv = trac.web._fcgi.WSGIServer(dispatch_request,  
     412          bindAddress = sockaddr, umask = 7) 
     413     fcgiserv.run() 
     414 
     415except SystemExit: 
     416    raise 
     417except Exception, e: 
     418    print 'Content-Type: text/plain\r\n\r\n', 
     419    print 'Oops...' 
     420    print 
     421    print 'Trac detected an internal error:' 
     422    print 
     423    print e 
     424    print 
     425    import traceback 
     426    import StringIO 
     427    tb = StringIO.StringIO() 
     428    traceback.print_exc(file=tb) 
     429    print tb.getvalue() 
     430 
     431}}} 
     432 
     4333) reload nginx and launch trac.fcgi like that: 
     434 
     435{{{ 
     436trac@trac.example ~ $ ./trac-standalone-fcgi.py  
     437}}} 
     438 
     439The above assumes that: 
     440 * 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) 
     445  * and patch from ticket #T7239 is applied, or you'll have to fix the socket file permissions every time 
     446 
     447Unfortunately nginx does not support variable expansion in fastcgi_pass directive.  
     448Thus it is not possible to serve multiple trac instances from one server block.  
     449 
     450If you worry enough about security, run trac instances under separate users.  
     451 
     452Another way to run trac as a FCGI external application is offered in ticket #T6224 
     453 
    313454---- 
    314 See also: TracCgi, TracModPython, TracInstall, TracGuide 
     455See also:  TracGuide, TracInstall, [wiki:TracModWSGI ModWSGI], [wiki:TracCgi CGI], [wiki:TracModPython ModPython], [http://trac.edgewall.org/wiki/TracNginxRecipe TracNginxRecipe]