Edgewall Software

Changes between Version 425 and Version 426 of TracInstall


Ignore:
Timestamp:
Apr 25, 2016, 4:47:45 AM (8 years ago)
Author:
Ryan J Ollos
Comment:

Improve documentation following discussion in gmessage:trac-users:MC9NzL1PMT4/4WJIVs9TQ40J.

Legend:

Unmodified
Added
Removed
Modified
  • TracInstall

    v425 v426  
    305305==== Mapping Static Resources
    306306
    307 Out 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''' as it causes abysmal performance.
    308 
    309 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 also can map requests for static resources directly to the directory on the file system, avoiding processing these requests by Trac itself.
    310 
    311 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.
    312 
    313 Note that in order to get those static resources on the filesystem, you need first to extract the relevant resources from Trac using the [TracAdmin trac-admin]` <environment> deploy` command:
     307Without additional configuration, Trac will handle requests for static resources such as stylesheets and images. For anything other than a TracStandalone deployment, this is not optimal as the web server can be set up to directly serve the static resources. For CGI setup, this is '''highly undesirable''' as it causes abysmal performance.
     308
     309Web 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 their location on the file system. We can map requests for static resources directly to directories on the file system, to avoid Trac processing the requests.
     310
     311There are two primary URL paths for static resources: `/chrome/common` and `/chrome/site`. Plugins can add their own resources, usually accessible at the `/chrome/<plugin>` path.
     312
     313A single `/chrome` alias can used if the static resources are extracted for all plugins. This means that the `deploy` command must be executed after installing or updating a plugin that provides static resources, or after modifying resources in the `$env/htdocs` directory. This is probably appropriate for most installations but may not be what you want if, for example, you wish to upload plugins through the //Plugins// administration page.
     314
     315The resources are extracted using the [TracAdmin trac-admin]` <environment> deploy` command:
    314316[[TracAdminHelp(deploy)]]
    315317
    316 The target `<directory>` will then contain an `htdocs` directory with:
    317  - `site/` - a copy of the environment's directory `htdocs/`
    318  - `common/` - the static resources of Trac itself
    319  - `<plugins>/` - one directory for each resource directory managed by the plugins enabled for this environment
    320 
    321 ===== Example: Apache and `ScriptAlias` #ScriptAlias-example
    322 
    323 Assuming the deployment has been done this way:
    324 {{{#!sh
    325 $ trac-admin /var/trac/env deploy /path/to/shared/trac
    326 }}}
    327 
    328 Add the following snippet to Apache configuration ''before'' the `ScriptAlias` or `WSGIScriptAlias` (which map all the other requests to the Trac application), changing paths to match your deployment:
     318The target `<directory>` will contain an `htdocs` directory with:
     319 - `common/` - the static resources of Trac
     320 - `site/` - a copy of the environment's `htdocs/` directory
     321 - `shared` - the static resources shared by multiple Trac environments, with a location defined by the `[inherit]` `htdocs_dir` option
     322 - `<plugin>/` - one directory for each resource directory provided by the plugins enabled for this environment
     323
     324The example that follows will create a single `/chrome` alias. If that isn't the correct approach for your installation you simply need to create more specific aliases:
    329325{{{#!apache
    330326Alias /trac/chrome/common /path/to/trac/htdocs/common
    331327Alias /trac/chrome/site /path/to/trac/htdocs/site
     328Alias /trac/chrome/shared /path/to/trac/htdocs/shared
     329Alias /trac/chrome/<plugin> /path/to/trac/htdocs/<plugin>
     330}}}
     331
     332===== Example: Apache and `ScriptAlias` #ScriptAlias-example
     333
     334Assuming the deployment has been done this way:
     335{{{#!sh
     336$ trac-admin /var/trac/env deploy /path/to/shared/trac
     337}}}
     338
     339Add the following snippet to Apache configuration, changing paths to match your deployment. The snippet must be placed ''before'' the `ScriptAlias` or `WSGIScriptAlias` directive, because those directives map all requests to the Trac application:
     340{{{#!apache
     341Alias /trac/chrome /path/to/trac/htdocs
    332342
    333343<Directory "/path/to/www/trac/htdocs">
     
    344354}}}
    345355
    346 If using mod_python, you might want to add this too, otherwise the alias will be ignored:
     356If using mod_python, add this too, otherwise the alias will be ignored:
    347357{{{#!apache
    348 <Location "/trac/chrome/common/">
     358<Location "/trac/chrome/common">
    349359  SetHandler None
    350360</Location>
    351361}}}
    352362
    353 Note that we mapped `/trac` part of the URL to the `trac.*cgi` script, and the path `/trac/chrome/common` is the path you have to append to that location to intercept requests to the static resources.
    354 
    355 Similarly, if you have static resources in a project's `htdocs` directory (which is referenced by `/trac/chrome/site` URL in themes), you can configure Apache to serve those resources (again, put this ''before'' the `ScriptAlias` or `WSGIScriptAlias` for the .*cgi scripts, and adjust names and locations to match your installation):
     363Alternatively, if you wish to serve static resources directly from your project's `htdocs` directory rather than the location to which the files are extracted with the `deploy` command, you can configure Apache to serve those resources. Again, put this ''before'' the `ScriptAlias` or `WSGIScriptAlias` for the .*cgi scripts, and adjust names and locations to match your installation:
    356364{{{#!apache
    357365Alias /trac/chrome/site /path/to/projectenv/htdocs
     
    370378}}}
    371379
    372 Alternatively to aliasing `/trac/chrome/common`, you can tell Trac to generate direct links for those static resources (and only those), using the [[TracIni#trac-section| [trac] htdocs_location]] configuration setting:
     380Another alternative to aliasing `/trac/chrome/common` is having Trac generate direct links for those static resources (and only those), using the [[TracIni#trac-section| [trac] htdocs_location]] configuration setting:
    373381{{{#!ini
    374382[trac]
     
    376384}}}
    377385
    378 Note that this makes it easy to have a dedicated domain serve those static resources, preferentially [http://code.google.com/speed/page-speed/docs/request.html#ServeFromCookielessDomain cookie-less].
     386Note that this makes it easy to have a dedicated domain serve those static resources, preferentially cookie-less.
    379387
    380388Of course, you still need to make the Trac `htdocs/common` 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: