Edgewall Software

Changes between Version 51 and Version 52 of TracCgi


Ignore:
Timestamp:
Feb 27, 2011, 3:16:36 PM (13 years ago)
Author:
Christian Boos
Comment:

Moved #MappingStaticResources to TracInstall#MappingStaticResources

Legend:

Unmodified
Added
Removed
Modified
  • TracCgi

    v51 v52  
    6060== Mapping Static Resources ==
    6161
    62 Out of the box, Trac will pass static resources such as style sheets or images through itself. For a CGI setup this is '''highly undesirable''', because this way CGI script is invoked for documents that could be much more efficiently served directly by web server.
    63 
    64 Web servers such as [http://httpd.apache.org/ Apache] allow you to create “Aliases” to resources, giving them a virtual URL that doesn't necessarily reflect the layout of the servers file system. We already used this capability by defining a `ScriptAlias` for the CGI script. We also can map requests for static resources directly to the directory on the file system, avoiding processing these requests by CGI script.
    65 
    66 There are two primary URL paths for static resources - `/chrome/common` and `/chrome/site`. Plugins can add their own resources usually accessible by `/chrome/plugin` path, so its important to override only known paths and not try to make universal `/chrome` alias for everything.
    67 
    68 Add the following snippet to Apache configuration '''before''' the `ScriptAlias` for the CGI script, changing paths to match your deployment:
    69 {{{
    70 Alias /trac/chrome/common /path/to/trac/htdocs/common
    71 Alias /trac/chrome/site /path/to/trac/htdocs/site
    72 <Directory "/path/to/www/trac/htdocs">
    73   Order allow,deny
    74   Allow from all
    75 </Directory>
    76 }}}
    77 
    78 If using mod_python, you might want to add this too (otherwise, the alias will be ignored):
    79 {{{
    80 <Location "/trac/chrome/common/">
    81   SetHandler None
    82 </Location>
    83 }}}
    84 
    85 Note that we mapped `/trac` part of the URL to the `trac.cgi` script, and the path `/chrome/common` is the path you have to append to that location to intercept requests to the static resources.
    86 
    87 For example, if Trac is mapped to `/cgi-bin/trac.cgi` on your server, the URL of the Alias should be `/cgi-bin/trac.cgi/chrome/common`, like so:
    88 
    89 {{{
    90 Alias /cgi-bin/trac.cgi/chrome/common /path/to/trac/htdocs/common
    91 }}}
    92 
    93 Similarly, if you have static resources in a project's htdocs directory (which is referenced by /chrome/site URL in themes), you can configure Apache to serve those resources (again, put this '''before''' the `ScriptAlias` for the CGI script, and adjust names and locations to match your installation):
    94 
    95 {{{
    96 Alias /trac/chrome/site /path/to/projectenv/htdocs
    97 <Directory "/path/to/projectenv/htdocs">
    98   Order allow,deny
    99   Allow from all
    100 </Directory>
    101 }}}
    102 
    103 Alternatively to hacking `/trac/chrome/site`, you can directly specify path to static resources using `htdocs_location` configuration option in [wiki:TracIni trac.ini]:
    104 {{{
    105 [trac]
    106 htdocs_location = http://yourhost.example.org/trac-htdocs
    107 }}}
    108 
    109 Trac will then use this URL when embedding static resources into HTML pages. Of course, you still need to make the Trac `htdocs` directory available through the web server at the specified URL, for example by copying (or linking) the directory into the document root of the web server:
    110 {{{
    111 $ ln -s /path/to/www/trac/htdocs /var/www/yourhost.example.org/trac-htdocs
    112 }}}
    113 
    114 Note that in order to get this `htdocs` directory, you need first to extract the relevant Trac resources using the `deploy` command of TracAdmin:
    115 [[TracAdminHelp(deploy)]]
    116 
     62See TracInstall#MappingStaticResources.
    11763
    11864== Adding Authentication ==