Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.ru/trac/tanchiki/wiki/TracStandalone?action=diff&version=2
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Mon Apr 11 21:27:30 2016
Êîäèðîâêà: IBM-866
TracStandalone (diff) òÀÓ Tanchiki

Changes between Version 1 and Version 2 of TracStandalone


Ignore:
Timestamp:
08/21/13 19:46:14 (3 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracStandalone

    v1 v2 ˆà
    11= Tracd =ˆà
    22ˆà
    3ˆàTracd is a lightweight standalone Trac web server. In most cases it's easier to setup and runs faster than the [wiki:TracCgi CGI script].ˆà
    ˆà3Tracd is a lightweight standalone Trac web server.ˆà
    ˆà4It can be used in a variety of situations, from a test or development server to a multiprocess setup behind another web server used as a load balancer.ˆà
    45ˆà
    56== Pros ==ˆà
    67ˆà
    78 * Fewer dependencies: You don't need to install apache or any other web-server.ˆà
    8ˆà * Fast: Should be almost as fast as the [wiki:TracModPython mod_python] version (and much faster than the [wiki:TracCgi CGI]).ˆà
    ˆà9 * Fast: Should be almost as fast as the [wiki:TracModPython mod_python] version (and much faster than the [wiki:TracCgi CGI]), even more so since version 0.12 where the HTTP/1.1 version of the protocol is enabled by defaultˆà
    910 * Automatic reloading: For development, Tracd can be used in ''auto_reload'' mode, which will automatically restart the server whenever you make a change to the code (in Trac itself or in a plugin).ˆà
    10ˆà  * Options for tracd: `-r, --auto-reload`ˆà
    1111ˆà
    1212== Cons ==ˆà
    1313ˆà
    14ˆà * Fewer features: Tracd implements a very simple web-server and is not as configurable or as scalable as Apache HTTPD.ˆà
    ˆà14 * Fewer features: Tracd implements a very simple web-server and is not as configurable or as scalable as Apache httpd.ˆà
    1515 * No native HTTPS support: [http://www.rickk.com/sslwrap/ sslwrap] can be used instead,ˆà
    1616   or [http://trac.edgewall.org/wiki/STunnelTracd stunnel -- a tutorial on how to use stunnel with tracd] or Apache with mod_proxy.ˆà
    òÀæ òÀæ ˆà
    4343== Installing as a Windows Service ==ˆà
    4444ˆà
    ˆà45=== Option 1 ===ˆà
    4546To install as a Windows service, get the [http://www.google.com/search?q=srvany.exe SRVANY] utility and run:ˆà
    4647{{{ˆà
    òÀæ òÀæ ˆà
    5960The spacing here is important.ˆà
    6061ˆà
    ˆà62{{{#!divˆà
    ˆà63Once the service is installed, it might be simpler to run the Registry Editor rather than use the `reg add` command documented above.  Navigate to:[[BR]]ˆà
    ˆà64`HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tracd\Parameters`ˆà
    ˆà65ˆà
    ˆà66Three (string) parameters are provided:ˆà
    ˆà67||!AppDirectory ||C:\Python26\ ||ˆà
    ˆà68||Application ||python.exe ||ˆà
    ˆà69||!AppParameters ||scripts\tracd-script.py -p 8080 ... ||ˆà
    ˆà70ˆà
    ˆà71Note that, if the !AppDirectory is set as above, the paths of the executable ''and'' of the script name and parameter values are relative to the directory.  This makes updating Python a little simpler because the change can be limited, here, to a single point.ˆà
    ˆà72(This is true for the path to the .htpasswd file, as well, despite the documentation calling out the /full/path/to/htpasswd; however, you may not wish to store that file under the Python directory.)ˆà
    ˆà73}}}ˆà
    ˆà74ˆà
    ˆà75For Windows 7 User, srvany.exe may not be an option, so you can use [http://www.google.com/search?q=winserv.exe WINSERV] utility and run:ˆà
    ˆà76{{{ˆà
    ˆà77"C:\path\to\winserv.exe" install tracd -displayname "tracd" -start auto "C:\path\to\python.exe" c:\path\to\python\scripts\tracd-script.py <your tracd parameters>"ˆà
    ˆà78ˆà
    ˆà79net start tracdˆà
    ˆà80}}}ˆà
    ˆà81ˆà
    ˆà82=== Option 2 ===ˆà
    ˆà83ˆà
    ˆà84Use [http://trac-hacks.org/wiki/WindowsServiceScript WindowsServiceScript], available at [http://trac-hacks.org/ Trac Hacks]. Installs, removes, starts, stops, etc. your Trac service.ˆà
    ˆà85ˆà
    ˆà86=== Option 3 ===ˆà
    ˆà87ˆà
    ˆà88also cygwin's cygrunsrv.exe can be used:ˆà
    ˆà89{{{ˆà
    ˆà90$ cygrunsrv --install tracd --path /cygdrive/c/Python27/Scripts/tracd.exe --args '--port 8000 --env-parent-dir E:\IssueTrackers\Trac\Projects'ˆà
    ˆà91$ net start tracdˆà
    ˆà92}}}ˆà
    ˆà93ˆà
    6194== Using Authentication ==ˆà
    6295ˆà
    63ˆàUsing tracd with Apache .htpasswd files:ˆà
    64ˆàˆà
    65ˆàTo create a .htpasswd file using htpasswd:ˆà
    66ˆàˆà
    ˆà96Tracd provides support for both Basic and Digest authentication. Digest is considered more secure. The examples below use Digest; to use Basic authentication, replace `--auth` with `--basic-auth` in the command line.ˆà
    ˆà97ˆà
    ˆà98The general format for using authentication is:ˆà
    ˆà99{{{ˆà
    ˆà100 $ tracd -p port --auth="base_project_dir,password_file_path,realm" project_pathˆà
    ˆà101}}}ˆà
    ˆà102where:ˆà
    ˆà103 * '''base_project_dir''': the base directory of the project specified as follows:ˆà
    ˆà104   * when serving multiple projects: ''relative'' to the `project_path`ˆà
    ˆà105   * when serving only a single project (`-s`): the name of the project directoryˆà
    ˆà106 Don't use an absolute path here as this won't work. ''Note:'' This parameter is case-sensitive even for environments on Windows.ˆà
    ˆà107 * '''password_file_path''': path to the password fileˆà
    ˆà108 * '''realm''': the realm name (can be anything)ˆà
    ˆà109 * '''project_path''': path of the projectˆà
    ˆà110ˆà
    ˆà111 * **`--auth`** in the above means use Digest authentication, replace `--auth` with `--basic-auth` if you want to use Basic auth.  Although Basic authentication does not require a "realm", the command parser does, so the second comma is required, followed directly by the closing quote for an empty realm name.ˆà
    ˆà112ˆà
    ˆà113Examples:ˆà
    ˆà114ˆà
    ˆà115{{{ˆà
    ˆà116 $ tracd -p 8080 \ˆà
    ˆà117   --auth="project1,/path/to/passwordfile,mycompany.com" /path/to/project1ˆà
    ˆà118}}}ˆà
    ˆà119ˆà
    ˆà120Of course, the password file can be be shared so that it is used for more than one project:ˆà
    ˆà121{{{ˆà
    ˆà122 $ tracd -p 8080 \ˆà
    ˆà123   --auth="project1,/path/to/passwordfile,mycompany.com" \ˆà
    ˆà124   --auth="project2,/path/to/passwordfile,mycompany.com" \ˆà
    ˆà125   /path/to/project1 /path/to/project2ˆà
    ˆà126}}}ˆà
    ˆà127ˆà
    ˆà128Another way to share the password file is to specify "*" for the project name:ˆà
    ˆà129{{{ˆà
    ˆà130 $ tracd -p 8080 \ˆà
    ˆà131   --auth="*,/path/to/users.htdigest,mycompany.com" \ˆà
    ˆà132   /path/to/project1 /path/to/project2ˆà
    ˆà133}}}ˆà
    ˆà134ˆà
    ˆà135=== Basic Authorization: Using a htpasswd password file ===ˆà
    ˆà136This section describes how to use `tracd` with Apache .htpasswd files.ˆà
    ˆà137ˆà
    ˆà138  Note: It is necessary (at least with Python 2.6) to install the fcrypt package in order toˆà
    ˆà139  decode the htpasswd format.  Trac source code attempt an `import crypt` first, but thereˆà
    ˆà140  is no such package for Python 2.6.ˆà
    ˆà141ˆà
    ˆà142To create a .htpasswd file use Apache's `htpasswd` command (see [#GeneratingPasswordsWithoutApache below] for a method to create these files without using Apache):ˆà
    67143{{{ˆà
    68144 $ sudo htpasswd -c /path/to/env/.htpasswd usernameˆà
    òÀæ òÀæ ˆà
    72148 $ sudo htpasswd /path/to/env/.htpasswd username2ˆà
    73149}}}ˆà
    74ˆàthen for starting the tracd (on windows skip the "=" after --basic-auth):ˆà
    75ˆà{{{ˆà
    76ˆà $ tracd -p 8080 --basic-auth=environmentname,/fullpath/environmentname/.htpasswd,/fullpath/environmentname /fullpath/environmentnameˆà
    77ˆà}}}ˆà
    78ˆàˆà
    79ˆàTracd provides support for both Basic and Digest authentication. The default is to use Digest; to use Basic authentication, replace `--auth` with `--basic-auth` in the examples below. (You must still specify a dialogic "realm", which can be an empty string by trailing the BASICAUTH with a comma.)ˆà
    80ˆàˆà
    81ˆà  ''Support for Basic authentication was added in version 0.9.''ˆà
    82ˆàˆà
    83ˆàThe general format for using authentication is (on windows skip the "=" after --auth):ˆà
    84ˆàˆà
    85ˆà{{{ˆà
    86ˆà $ tracd -p port --auth=base_project_dir,password_file_path,realm project_pathˆà
    87ˆà}}}ˆà
    88ˆàˆà
    89ˆàwhere:ˆà
    90ˆàˆà
    91ˆà * '''base_project_dir''' is the base directory of the project; note: this doesn't refer to the project name, and it is case-sensitive even for windows environmentsˆà
    92ˆà * '''password_file_path''' path of the password fileˆà
    93ˆà * '''realm''' realmˆà
    94ˆà * '''project_path''' path of the projectˆà
    95ˆàˆà
    96ˆàExample (on windows skip the "=" after --auth):ˆà
    97ˆàˆà
    98ˆà{{{ˆà
    99ˆà $ tracd -p 8080 \ˆà
    100ˆà   --auth=project1,/path/to/users.htdigest,mycompany.com /path/to/project1ˆà
    101ˆà}}}ˆà
    102ˆàOf course, the digest file can be be shared so that it is used for more than one project:ˆà
    103ˆà{{{ˆà
    104ˆà $ tracd -p 8080 \ˆà
    105ˆà   --auth=project1,/path/to/users.htdigest,mycompany.com \ˆà
    106ˆà   --auth=project2,/path/to/users.htdigest,mycompany.com \ˆà
    107ˆà   /path/to/project1 /path/to/project2ˆà
    108ˆà}}}ˆà
    109ˆàˆà
    110ˆàAnother way to share the digest file is to specify "*"ˆà
    111ˆàfor the project name:ˆà
    112ˆà{{{ˆà
    113ˆà $ tracd -p 8080 \ˆà
    114ˆà   --auth="*",/path/to/users.htdigest,mycompany.com \ˆà
    115ˆà   /path/to/project1 /path/to/project2ˆà
    116ˆà}}}ˆà
    117ˆàIf using the `-s` parameter for serving a Trac environment from the root of a domain, one must use `*` for the project nameˆà
    118ˆàˆà
    119ˆà== How to set up an htdigest password file ==ˆà
    ˆà150ˆà
    ˆà151Then to start `tracd` run something like this:ˆà
    ˆà152{{{ˆà
    ˆà153 $ tracd -p 8080 --basic-auth="projectdirname,/fullpath/environmentname/.htpasswd,realmname" /fullpath/environmentnameˆà
    ˆà154}}}ˆà
    ˆà155ˆà
    ˆà156For example:ˆà
    ˆà157{{{ˆà
    ˆà158 $ tracd -p 8080 --basic-auth="testenv,/srv/tracenv/testenv/.htpasswd,My Test Env" /srv/tracenv/testenvˆà
    ˆà159}}}ˆà
    ˆà160''Note:'' You might need to pass "-m" as a parameter to htpasswd on some platforms (OpenBSD).ˆà
    ˆà161ˆà
    ˆà162=== Digest authentication: Using a htdigest password file ===ˆà
    120163ˆà
    121164If you have Apache available, you can use the htdigest command to generate the password file. Type 'htdigest' to get some usage instructions, or read [http://httpd.apache.org/docs/2.0/programs/htdigest.html this page] from the Apache manual to get precise instructions.  You'll be prompted for a password to enter for each user that you create.  For the name of the password file, you can use whatever you like, but if you use something like `users.htdigest` it will remind you what the file contains. As a suggestion, put it in your <projectname>/conf folder along with the [TracIni trac.ini] file.ˆà
    òÀæ òÀæ ˆà
    123166Note that you can start tracd without the --auth argument, but if you click on the ''Login'' link you will get an error.ˆà
    124167ˆà
    125ˆà== Generating Passwords Without Apache ==ˆà
    126ˆàˆà
    127ˆàIf you don't have Apache available, you can use this simple Python script to generate your passwords:ˆà
    ˆà168=== Generating Passwords Without Apache ===ˆà
    ˆà169ˆà
    ˆà170Basic Authorization can be accomplished via this [http://aspirine.org/htpasswd_en.html online HTTP Password generator].  Copy the generated password-hash line to the .htpasswd file on your system. Note that Windows Python lacks the "crypt" module that is the default hash type for htpasswd ; Windows Python can grok MD5 password hashes just fine and you should use MD5.ˆà
    ˆà171ˆà
    ˆà172You can use this simple Python script to generate a '''digest''' password file:ˆà
    128173ˆà
    129174{{{ˆà
    òÀæ òÀæ ˆà
    159204}}}ˆà
    160205ˆà
    161ˆàNote: If you use the above script you must use the --auth option to tracd, not --basic-auth, and you must set the realm in the --auth value to 'trac' (without the quotes). Example usage (assuming you saved the script as trac-digest.py):ˆà
    ˆà206Note: If you use the above script you must set the realm in the `--auth` argument to '''`trac`'''. Example usage (assuming you saved the script as trac-digest.py):ˆà
    162207ˆà
    163208{{{ˆà
    òÀæ òÀæ ˆà
    166211}}}ˆà
    167212ˆà
    168ˆàNote: If you would like to use --basic-auth you need to use htpasswd tool from apache server to generate .htpasswd file. The remaining part is similar but make sure to use empty realm (i.e. coma after path). When using on Windows make sure to use -m option for it (did not tested it on *nix, so not sure if that is the case there).  If you do not have Apache, [trac:source:/tags/trac-0.11b2/contrib/htpasswd.py htpasswd.py] may help.  (Note that it requires a `crypt` or `fcrypt` module; see the source comments for details.)ˆà
    169ˆàˆà
    170ˆàIt is possible to use md5sum utility to generate digest-password file using such method:ˆà
    171ˆà{{{ˆà
    172ˆà $ printf "${user}:trac:${password}" | md5sum - >>user.htdigestˆà
    173ˆà}}}ˆà
    174ˆàand manually delete " -" from the end and add "${user}:trac:" to the start of line from 'to-file'.ˆà
    ˆà213==== Using `md5sum`ˆà
    ˆà214It is possible to use `md5sum` utility to generate digest-password file:ˆà
    ˆà215{{{ˆà
    ˆà216user=ˆà
    ˆà217realm=ˆà
    ˆà218password=ˆà
    ˆà219path_to_file=ˆà
    ˆà220echo ${user}:${realm}:$(printf "${user}:${realm}:${password}" | md5sum - | sed -e 's/\s\+-//') > ${path_to_file}ˆà
    ˆà221}}}ˆà
    ˆà222ˆà
    ˆà223== Reference ==ˆà
    ˆà224ˆà
    ˆà225Here's the online help, as a reminder (`tracd --help`):ˆà
    ˆà226{{{ˆà
    ˆà227Usage: tracd [options] [projenv] ...ˆà
    ˆà228ˆà
    ˆà229Options:ˆà
    ˆà230  --version             show program's version number and exitˆà
    ˆà231  -h, --help            show this help message and exitˆà
    ˆà232  -a DIGESTAUTH, --auth=DIGESTAUTHˆà
    ˆà233                        [projectdir],[htdigest_file],[realm]ˆà
    ˆà234  --basic-auth=BASICAUTHˆà
    ˆà235                        [projectdir],[htpasswd_file],[realm]ˆà
    ˆà236  -p PORT, --port=PORT  the port number to bind toˆà
    ˆà237  -b HOSTNAME, --hostname=HOSTNAMEˆà
    ˆà238                        the host name or IP address to bind toˆà
    ˆà239  --protocol=PROTOCOL   http|scgi|ajp|fcgiˆà
    ˆà240  -q, --unquote         unquote PATH_INFO (may be needed when using ajp)ˆà
    ˆà241  --http10              use HTTP/1.0 protocol version instead of HTTP/1.1ˆà
    ˆà242  --http11              use HTTP/1.1 protocol version (default)ˆà
    ˆà243  -e PARENTDIR, --env-parent-dir=PARENTDIRˆà
    ˆà244                        parent directory of the project environmentsˆà
    ˆà245  --base-path=BASE_PATHˆà
    ˆà246                        the initial portion of the request URL's "path"ˆà
    ˆà247  -r, --auto-reload     restart automatically when sources are modifiedˆà
    ˆà248  -s, --single-env      only serve a single project without the project listˆà
    ˆà249  -d, --daemonize       run in the background as a daemonˆà
    ˆà250  --pidfile=PIDFILE     When daemonizing, file to which to write pidˆà
    ˆà251  --umask=MASK          When daemonizing, file mode creation mask to use, inˆà
    ˆà252                        octal notation (default 022)ˆà
    ˆà253}}}ˆà
    ˆà254ˆà
    ˆà255Use the -d option so that tracd doesn't hang if you close the terminal window where tracd was started.ˆà
    175256ˆà
    176257== Tips ==ˆà
    òÀæ òÀæ ˆà
    178259=== Serving static content ===ˆà
    179260ˆà
    180ˆàIf `tracd` is the only webserver used for the project, ˆà
    ˆà261If `tracd` is the only web server used for the project, ˆà
    181262it can also be used to distribute static content ˆà
    182263(tarballs, Doxygen documentation, etc.)ˆà
    òÀæ òÀæ ˆà
    187268Example: given a `$TRAC_ENV/htdocs/software-0.1.tar.gz` file,ˆà
    188269the corresponding relative URL would be `/<project_name>/chrome/site/software-0.1.tar.gz`, ˆà
    189ˆàwhich in turn can be written using the relative link syntaxˆà
    190ˆàin the Wiki: `[/<project_name>/chrome/site/software-0.1.tar.gz]` ˆà
    191ˆàˆà
    192ˆàSince 0.10, Trac supports a new `htdocs:` TracLinks ˆà
    193ˆàsyntax for the above. With this, the example link above can be written simply ˆà
    194ˆà`htdocs:software-0.1.tar.gz`. ˆà
    195ˆàˆà
    196ˆà=== Using apache rewrite rules ===ˆà
    197ˆàIn some situations when you choose to use tracd behind apache, you might experience issues with redirects, like being redirected to URLs with the wrong host or protocol. In this case (and only in this case), setting the `[trac] use_base_url_for_redirect` to `true` can help, as this will force Trac to use the value of `[trac] base_url` for doing the redirects.ˆà
    ˆà270which in turn can be written as `htdocs:software-0.1.tar.gz` (TracLinks syntax) or `[/<project_name>/chrome/site/software-0.1.tar.gz]` (relative link syntax). ˆà
    ˆà271ˆà
    ˆà272 ''Support for `htdocs:` TracLinks syntax was added in version 0.10''ˆà
    ˆà273ˆà
    ˆà274=== Using tracd behind a proxyˆà
    ˆà275ˆà
    ˆà276In some situations when you choose to use tracd behind Apache or another web server.ˆà
    ˆà277ˆà
    ˆà278In this situation, you might experience issues with redirects, like being redirected to URLs with the wrong host or protocol. In this case (and only in this case), setting the `[trac] use_base_url_for_redirect` to `true` can help, as this will force Trac to use the value of `[trac] base_url` for doing the redirects.ˆà
    ˆà279ˆà
    ˆà280If you're using the AJP protocol to connect with `tracd` (which is possible if you have flup installed), then you might experience problems with double quoting. Consider adding the `--unquote` parameter.ˆà
    ˆà281ˆà
    ˆà282See also [trac:TracOnWindowsIisAjp], [trac:TracNginxRecipe].ˆà
    ˆà283ˆà
    ˆà284=== Authentication for tracd behind a proxyˆà
    ˆà285It is convenient to provide central external authentication to your tracd instances, instead of using {{{--basic-auth}}}. There is some discussion about this in #9206.ˆà
    ˆà286ˆà
    ˆà287Below is example configuration based on Apache 2.2, mod_proxy, mod_authnz_ldap.ˆà
    ˆà288ˆà
    ˆà289First we bring tracd into Apache's location namespace.ˆà
    ˆà290ˆà
    ˆà291{{{ˆà
    ˆà292<Location /project/proxified>ˆà
    ˆà293        Require ldap-group cn=somegroup, ou=Groups,dc=domain.comˆà
    ˆà294        Require ldap-user somespecificusertooˆà
    ˆà295        ProxyPass http://localhost:8101/project/proxified/ˆà
    ˆà296        # Turns out we don't really need complicated RewriteRules here at allˆà
    ˆà297        RequestHeader set REMOTE_USER %{REMOTE_USER}sˆà
    ˆà298</Location>ˆà
    ˆà299}}}ˆà
    ˆà300ˆà
    ˆà301Then we need a single file plugin to recognize HTTP_REMOTE_USER header as valid authentication source. HTTP headers like '''HTTP_FOO_BAR''' will get converted to '''Foo-Bar''' during processing. Name it something like '''remote-user-auth.py''' and drop it into '''proxified/plugins''' directory:ˆà
    ˆà302{{{ˆà
    ˆà303#!pythonˆà
    ˆà304from trac.core import *ˆà
    ˆà305from trac.config import BoolOptionˆà
    ˆà306from trac.web.api import IAuthenticatorˆà
    ˆà307ˆà
    ˆà308class MyRemoteUserAuthenticator(Component):ˆà
    ˆà309ˆà
    ˆà310    implements(IAuthenticator)ˆà
    ˆà311ˆà
    ˆà312    obey_remote_user_header = BoolOption('trac', 'obey_remote_user_header', 'false', ˆà
    ˆà313               """Whether the 'Remote-User:' HTTP header is to be trusted for user logins ˆà
    ˆà314                (''since ??.??').""") ˆà
    ˆà315ˆà
    ˆà316    def authenticate(self, req):ˆà
    ˆà317        if self.obey_remote_user_header and req.get_header('Remote-User'): ˆà
    ˆà318            return req.get_header('Remote-User') ˆà
    ˆà319        return Noneˆà
    ˆà320ˆà
    ˆà321}}}ˆà
    ˆà322ˆà
    ˆà323Add this new parameter to your TracIni:ˆà
    ˆà324{{{ˆà
    ˆà325...ˆà
    ˆà326[trac]ˆà
    ˆà327...ˆà
    ˆà328obey_remote_user_header = trueˆà
    ˆà329...ˆà
    ˆà330}}}ˆà
    ˆà331ˆà
    ˆà332Run tracd:ˆà
    ˆà333{{{ˆà
    ˆà334tracd -p 8101 -r -s proxified --base-path=/project/proxifiedˆà
    ˆà335}}}ˆà
    198336ˆà
    199337=== Serving a different base path than / ===ˆà
    òÀæ òÀæ ˆà
    204342ˆà
    205343----ˆà
    206ˆàSee also: TracInstall, TracCgi, TracModPython, TracGuide, [trac:TracOnWindowsStandalone?version=13#RunningTracdasservice Running tracd.exe as a Windows service]ˆà
    ˆà344See also: TracInstall, TracCgi, TracModPython, TracGuide, [trac:TracOnWindowsStandalone#RunningTracdasservice Running tracd.exe as a Windows service]ˆà