v1 | v2 | |
---|---|---|
1 | = Trac を FastCGI で使用する = |
|
1 | = Trac を FastCGI で使用する = #TracwithFastCGI | |
2 | 2 | |
3 | 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 | 4 | |
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 | |
6 | 9 | |
7 | 10 | Apache で利用可能な FastCGI モジュールは 2 種類あります: `mod_fastcgi` と |
8 | `mod_fcgid` です。 |
|
9 | は `mod_fastcgi` のディレクティブです; `DefaultInitEnv` は `mod_f |
|
11 | `mod_fcgid` です。これ以降に書かれている `FastCgiIpcDir` と `FastCgiConfig` ディレクティブ | |
12 | は `mod_fastcgi` のディレクティブです; `DefaultInitEnv` は `mod_fcgid` | |
10 | 13 | のディレクティブです。 |
11 | 14 | |
… | … | |
62 | 65 | `trac.fcgi` をコピーして、ファイル名を適切に変更し、上記のコードをそれぞれのスクリプトに追記します。 |
63 | 66 | |
64 | == 単純な Lighttpd の設定 == | |
67 | この [https://coderanger.net/~coderanger/httpd/fcgi_example.conf fcgid 設定例] を見たところ、 !ScriptAlias ディレクティブでは末尾の / も含めて、このように設定する: | |
68 | {{{ | |
69 | ScriptAlias / /srv/tracsite/cgi-bin/trac.fcgi/ | |
70 | }}} | |
71 | ||
72 | == Simple Cherokee Configuration == | |
73 | ||
74 | The configuration on Cherokee's side is quite simple. You will only need to know that you can spawn Trac as an SCGI process. | |
75 | You can either start it manually, or better yet, automatically by letting Cherokee spawn the server whenever it is down. | |
76 | First set up an information source in cherokee-admin with a local interpreter. | |
77 | ||
78 | {{{ | |
79 | Host: | |
80 | localhost:4433 | |
81 | ||
82 | Interpreter: | |
83 | /usr/bin/tracd —single-env —daemonize —protocol=scgi —hostname=localhost —port=4433 /path/to/project/ | |
84 | }}} | |
85 | ||
86 | If 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 | ||
88 | After 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 | |
65 | 92 | |
66 | 93 | FastCGI フロントエンドは最初 [http://www.lighttpd.net/ lighttpd] のような、 Apache 以外の Web サーバのために開発されました。 |
… | … | |
69 | 96 | 他の Web サーバに比べて CPU や、メモリの占有率がとても少ないです。 |
70 | 97 | |
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 | |
101 | var.fcgi_binary="/path/to/cgi-bin/trac.fcgi" # 0.10 name of prior fcgi executable | |
73 | 102 | fastcgi.server = ("/trac" => |
103 | ||
74 | 104 | ("trac" => |
75 | 105 | ("socket" => "/tmp/trac-fastcgi.sock", |
76 | "bin-path" => |
|
106 | "bin-path" => fcgi_binary, | |
77 | 107 | "check-local" => "disable", |
78 | 108 | "bin-environment" => |
… | … | |
92 | 122 | ("first" => |
93 | 123 | ("socket" => "/tmp/trac-fastcgi-first.sock", |
94 | "bin-path" => |
|
124 | "bin-path" => fcgi_binary, | |
95 | 125 | "check-local" => "disable", |
96 | 126 | "bin-environment" => |
… | … | |
101 | 131 | ("second" => |
102 | 132 | ("socket" => "/tmp/trac-fastcgi-second.sock", |
103 | "bin-path" => |
|
133 | "bin-path" => fcgi_binary, | |
104 | 134 | "check-local" => "disable", |
105 | 135 | "bin-environment" => |
… | … | |
110 | 140 | }}} |
111 | 141 | 各フィールドの値が異なることに注意して下さい。もし `.fcgi` スクリプトに |
112 | 環境変数を設定するほうが好ましい場合は、 `trac.fcgi` をコピー |
|
142 | 環境変数を設定するほうが好ましい場合は、 `trac.fcgi` をコピー/名前変更をして下さい。例として、 | |
113 | 143 | `first.fcgi` と `second.fcgi` が上記の設定では参照されるようにします。 |
114 | 144 | 上記の設定で、両方のプロジェクトが 同じ `trac.fcgi` スクリプトで起動していても、 |
115 | 145 | 異なるプロセスになることに注意して下さい。 |
116 | 146 | {{{ |
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 より '''先に''' ロードされる設定になっていない場合、サーバはユーザの認証に失敗します。 | |
121 | 149 | }}} |
122 | 150 | 認証のために lighttpd.conf の 'server.modules' 中で mod_auth を有効にして、 auth.backend と認証方法を選択して下さい: |
… | … | |
177 | 205 | ("trac" => |
178 | 206 | ("socket" => "/tmp/trac-fastcgi.sock", |
179 | "bin-path" => |
|
207 | "bin-path" => fcgi_binary, | |
180 | 208 | "check-local" => "disable", |
181 | 209 | "bin-environment" => |
… | … | |
196 | 224 | ( |
197 | 225 | "socket" => "/tmp/trac.sock", |
198 | "bin-path" => |
|
226 | "bin-path" => fcgi_binary, | |
199 | 227 | "check-local" => "disable", |
200 | 228 | "bin-environment" => |
… | … | |
222 | 250 | ("trac" => |
223 | 251 | ("socket" => "/tmp/trac-fastcgi.sock", |
224 | "bin-path" => |
|
252 | "bin-path" => fcgi_binary, | |
225 | 253 | "check-local" => "disable", |
226 | 254 | "bin-environment" => |
… | … | |
244 | 272 | |
245 | 273 | |
246 | == 簡単な |
|
247 | ||
248 | FastCGI フロントエンドは |
|
249 | ||
250 | ||
274 | == 簡単な !LiteSpeeed の設定 == #SimpleLiteSpeedConfiguration | |
275 | ||
276 | FastCGI フロントエンドは [http://www.litespeedtech.com/ LiteSpeed] のような、 Apache 以外の Web サーバのために開発されました。 | |
277 | ||
278 | !LiteSpeed Web サーバはイベント駆動、非同期型であり、Apache に代わるものとしてセキュアで拡張可能になるようにゼロからデザインされています。そして、最低限のリソースで操作できます。 !LiteSpeed は Apache の設定ファイルから直接操作でき、ビジネスに不可欠な環境をターゲットにしています。 | |
251 | 279 | |
252 | 280 | セットアップ |
… | … | |
293 | 321 | URI: /trac/ <--- URI path to bind to python fcgi app we created |
294 | 322 | Fast CGI App: [VHost Level] MyTractFCGI <--- select the trac fcgi extapp we just created |
295 | Realm: TracUserDB <--- only if (4) is set. select rea |
|
323 | Realm: TracUserDB <--- only if (4) is set. select realm created in (4) | |
296 | 324 | }}} |
297 | 325 | |
… | … | |
305 | 333 | }}} |
306 | 334 | |
307 | 7) [http://trac.edgewall.org/wiki/LiteSpeed LiteSpeed] を "lswsctrl restart" で再起動し、新しい Trac プロジェクトに以下の URL でアクセスします: | |
335 | 7) !LiteSpeed を "lswsctrl restart" で再起動し、新しい Trac プロジェクトに以下の URL でアクセスします: | |
336 | ||
308 | 337 | |
309 | 338 | {{{ |
… | … | |
311 | 340 | }}} |
312 | 341 | |
342 | === Simple Nginx Configuration === | |
343 | ||
344 | 1) 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 | ||
399 | 2) Modified trac.fcgi: | |
400 | ||
401 | {{{ | |
402 | #!/usr/bin/env python | |
403 | import os | |
404 | sockaddr = '/home/trac/run/instance.sock' | |
405 | os.environ['TRAC_ENV'] = '/home/trac/instance' | |
406 | ||
407 | try: | |
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 | ||
415 | except SystemExit: | |
416 | raise | |
417 | except Exception, e: | |
418 | print 'Content-Type: text/plain\r\n\r\n', | |
419 | print 'Oops...' | |
420 | ||
421 | print 'Trac detected an internal error:' | |
422 | ||
423 | print e | |
424 | ||
425 | import traceback | |
426 | import StringIO | |
427 | tb = StringIO.StringIO() | |
428 | traceback.print_exc(file=tb) | |
429 | print tb.getvalue() | |
430 | ||
431 | }}} | |
432 | ||
433 | 3) reload nginx and launch trac.fcgi like that: | |
434 | ||
435 | {{{ | |
436 | trac@trac.example ~ $ ./trac-standalone-fcgi.py | |
437 | }}} | |
438 | ||
439 | The 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 | ||
447 | Unfortunately nginx does not support variable expansion in fastcgi_pass directive. | |
448 | Thus it is not possible to serve multiple trac instances from one server block. | |
449 | ||
450 | If you worry enough about security, run trac instances under separate users. | |
451 | ||
452 | Another way to run trac as a FCGI external application is offered in ticket #T6224 | |
453 | ||
313 | 454 | ---- |
314 | See also: |
|
455 | See also: TracGuide, TracInstall, [wiki:TracModWSGI ModWSGI], [wiki:TracCgi CGI], [wiki:TracModPython ModPython], [http://trac.edgewall.org/wiki/TracNginxRecipe TracNginxRecipe] |