Edgewall Software

Changes between Version 45 and Version 46 of 1.1/TracInstall


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

Merge TracInstall@426.

Legend:

Unmodified
Added
Removed
Modified
  • 1.1/TracInstall

    v45 v46  
    294294==== Mapping Static Resources
    295295
    296 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''' and will cause abysmal performance).
    297 
    298 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.
    299 
    300 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.
    301 
    302 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 `deploy` command:
     296Without 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.
     297
     298Web 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.
     299
     300There 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.
     301
     302A 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.
     303
     304The resources are extracted using the [TracAdmin trac-admin]` <environment> deploy` command:
    303305[[TracAdminHelp(deploy)]]
    304306
    305 The target `<directory>` will then contain an `htdocs` directory with:
    306  - `site/` - a copy of the environment's directory `htdocs/`
    307  - `common/` - the static resources of Trac itself
    308  - `<plugins>/` - one directory for each resource directory managed by the plugins enabled for this environment
    309 
    310 ===== Example: Apache and `ScriptAlias` #ScriptAlias-example
    311 
    312 Assuming the deployment has been done this way:
    313 {{{#!sh
    314 $ trac-admin /var/trac/env deploy /path/to/shared/trac
    315 }}}
    316 
    317 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:
     307The target `<directory>` will contain an `htdocs` directory with:
     308 - `common/` - the static resources of Trac
     309 - `site/` - a copy of the environment's `htdocs/` directory
     310 - `shared` - the static resources shared by multiple Trac environments, with a location defined by the `[inherit]` `htdocs_dir` option
     311 - `<plugin>/` - one directory for each resource directory provided by the plugins enabled for this environment
     312
     313The 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:
    318314{{{#!apache
    319315Alias /trac/chrome/common /path/to/trac/htdocs/common
    320316Alias /trac/chrome/site /path/to/trac/htdocs/site
     317Alias /trac/chrome/shared /path/to/trac/htdocs/shared
     318Alias /trac/chrome/<plugin> /path/to/trac/htdocs/<plugin>
     319}}}
     320
     321===== Example: Apache and `ScriptAlias` #ScriptAlias-example
     322
     323Assuming the deployment has been done this way:
     324{{{#!sh
     325$ trac-admin /var/trac/env deploy /path/to/shared/trac
     326}}}
     327
     328Add 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:
     329{{{#!apache
     330Alias /trac/chrome /path/to/trac/htdocs
    321331
    322332<Directory "/path/to/www/trac/htdocs">
     
    333343}}}
    334344
    335 If using mod_python, you might want to add this too (otherwise, the alias will be ignored):
     345If using mod_python, add this too, otherwise the alias will be ignored:
    336346{{{#!apache
    337 <Location "/trac/chrome/common/">
     347<Location "/trac/chrome/common">
    338348  SetHandler None
    339349</Location>
    340350}}}
    341351
    342 Note that we mapped the `/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.
    343 
    344 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):
     352Alternatively, 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:
    345353{{{#!apache
    346354Alias /trac/chrome/site /path/to/projectenv/htdocs
     
    359367}}}
    360368
    361 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:
     369Another 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:
    362370{{{#!ini
    363371[trac]
    364372htdocs_location = http://static.example.org/trac-common/
    365373}}}
    366 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]).
     374
     375Note that this makes it easy to have a dedicated domain serve those static resources, preferentially cookie-less.
    367376
    368377Of 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: