Edgewall Software

Changes between Version 334 and Version 335 of TracInstall


Ignore:
Timestamp:
Feb 27, 2011, 2:15:14 PM (13 years ago)
Author:
Christian Boos
Comment:

Moved TracCgi@51#MappingStaticResources to TracInstall#MappingStaticResources

Legend:

Unmodified
Added
Removed
Modified
  • TracInstall

    v334 v335  
    286286}}}
    287287
     288
     289==== Mapping Static Resources ====
     290
     291Out of the box, Trac will pass static resources such as style sheets or images through itself. For anything but a tracd only based deployment, this is far from optimal as the web server could be set up to directly serve those static resources (for CGI setup, this is '''highly undesirable''' and will cause abysmal performance).
     292
     293Web 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 also can map requests for static resources directly to the directory on the file system, avoiding processing these requests by Trac itself.
     294
     295There 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.
     296
     297===== Example: Apache and `ScriptAlias` =====
     298
     299Add the following snippet to Apache configuration '''before''' the `ScriptAlias` for the CGI script, changing paths to match your deployment:
     300{{{
     301Alias /trac/chrome/common /path/to/trac/htdocs/common
     302Alias /trac/chrome/site /path/to/trac/htdocs/site
     303<Directory "/path/to/www/trac/htdocs">
     304  Order allow,deny
     305  Allow from all
     306</Directory>
     307}}}
     308
     309If using mod_python, you might want to add this too (otherwise, the alias will be ignored):
     310{{{
     311<Location "/trac/chrome/common/">
     312  SetHandler None
     313</Location>
     314}}}
     315
     316Note 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.
     317
     318For 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:
     319
     320{{{
     321Alias /cgi-bin/trac.cgi/chrome/common /path/to/trac/htdocs/common
     322}}}
     323
     324Similarly, 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):
     325
     326{{{
     327Alias /trac/chrome/site /path/to/projectenv/htdocs
     328<Directory "/path/to/projectenv/htdocs">
     329  Order allow,deny
     330  Allow from all
     331</Directory>
     332}}}
     333
     334Alternatively to hacking `/trac/chrome/site`, you can directly specify path to static resources using `htdocs_location` configuration option in [wiki:TracIni trac.ini]:
     335{{{
     336[trac]
     337htdocs_location = http://yourhost.example.org/trac-htdocs
     338}}}
     339
     340Trac 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:
     341{{{
     342$ ln -s /path/to/www/trac/htdocs /var/www/yourhost.example.org/trac-htdocs
     343}}}
     344
     345Note that in order to get this `htdocs` directory, you need first to extract the relevant Trac resources using the `deploy` command of TracAdmin:
     346[[TracAdminHelp(deploy)]]
     347
     348
    288349==== Setting up the Plugin Cache ====
    289350