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: |
| 306 | Without 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 | |
| 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 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 | |
| 310 | There 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 | |
| 312 | A 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 | |
| 314 | The resources are extracted using the [TracAdmin trac-admin]` <environment> deploy` command: |
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: |
| 317 | The 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 | |
| 323 | The 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: |
| 327 | Alias /trac/chrome/shared /path/to/trac/htdocs/shared |
| 328 | Alias /trac/chrome/<plugin> /path/to/trac/htdocs/<plugin> |
| 329 | }}} |
| 330 | |
| 331 | ===== Example: Apache and `ScriptAlias` #ScriptAlias-example |
| 332 | |
| 333 | Assuming the deployment has been done this way: |
| 334 | {{{#!sh |
| 335 | $ trac-admin /var/trac/env deploy /path/to/shared/trac |
| 336 | }}} |
| 337 | |
| 338 | Add 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 |
| 340 | Alias /trac/chrome /path/to/trac/htdocs |
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): |
| 362 | Alternatively, 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: |