Changes between Version 7 and Version 8 of TracInstall


Ignore:
Timestamp:
Jun 25, 2016, 8:15:23 PM (8 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracInstall

    v7 v8  
    304304==== Mapping Static Resources
    305305
    306 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.
    307 
    308 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.
    309 
    310 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.
    311 
    312 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:
     306Without 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.
     307
     308Web 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.
     309
     310There 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.
     311
     312A 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.
     313
     314The resources are extracted using the [TracAdmin trac-admin]` <environment> deploy` command:
    313315[[TracAdminHelp(deploy)]]
    314316
    315 The target `<directory>` will then contain an `htdocs` directory with:
    316  - `site/` - a copy of the environment's directory `htdocs/`
    317  - `common/` - the static resources of Trac itself
    318  - `<plugins>/` - one directory for each resource directory managed by the plugins enabled for this environment
    319 
    320 ===== Example: Apache and `ScriptAlias` #ScriptAlias-example
    321 
    322 Assuming the deployment has been done this way:
    323 {{{#!sh
    324 $ trac-admin /var/trac/env deploy /path/to/shared/trac
    325 }}}
    326 
    327 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:
     317The target `<directory>` will contain an `htdocs` directory with:
     318 - `common/` - the static resources of Trac
     319 - `site/` - a copy of the environment's `htdocs/` directory
     320 - `shared` - the static resources shared by multiple Trac environments, with a location defined by the `[inherit]` `htdocs_dir` option
     321 - `<plugin>/` - one directory for each resource directory provided by the plugins enabled for this environment
     322
     323The 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:
    328324{{{#!apache
    329325Alias /trac/chrome/common /path/to/trac/htdocs/common
    330326Alias /trac/chrome/site /path/to/trac/htdocs/site
     327Alias /trac/chrome/shared /path/to/trac/htdocs/shared
     328Alias /trac/chrome/<plugin> /path/to/trac/htdocs/<plugin>
     329}}}
     330
     331===== Example: Apache and `ScriptAlias` #ScriptAlias-example
     332
     333Assuming the deployment has been done this way:
     334{{{#!sh
     335$ trac-admin /var/trac/env deploy /path/to/shared/trac
     336}}}
     337
     338Add 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:
     339{{{#!apache
     340Alias /trac/chrome /path/to/trac/htdocs
    331341
    332342<Directory "/path/to/www/trac/htdocs">
     
    343353}}}
    344354
    345 If using mod_python, you might want to add this too, otherwise the alias will be ignored:
     355If using mod_python, add this too, otherwise the alias will be ignored:
    346356{{{#!apache
    347 <Location "/trac/chrome/common/">
     357<Location "/trac/chrome/common">
    348358  SetHandler None
    349359</Location>
    350360}}}
    351361
    352 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.
    353 
    354 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):
     362Alternatively, 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:
    355363{{{#!apache
    356364Alias /trac/chrome/site /path/to/projectenv/htdocs
     
    369377}}}
    370378
    371 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:
     379Another 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:
    372380{{{#!ini
    373381[trac]
     
    375383}}}
    376384
    377 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].
     385Note that this makes it easy to have a dedicated domain serve those static resources, preferentially cookie-less.
    378386
    379387Of 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: