Modify

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#12239 closed task (fixed)

Configure Apache to serve attachments

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Component: TracHacks
Severity: normal Keywords:
Cc: osimons, Steffen Hoffmann, Michael Renzmann, Jun Omae Trac Release:

Description (last modified by Ryan J Ollos)

The following are excerpts from an email discussion that took place after upgrading to Trac 1.0.


I previously mentioned the problem with attachments not having been migrated from the $TRACENV/attachments directory to $TRACENV/files/attachments. After re-running one of the database upgrade steps, the attachments were still not displaying, however from what I saw in the logs with the log level set to debug, it seemed like Trac was serving up the file, and there was something wrong with the Apache configuration. Further evidence was that Trac no longer displayed a TracError when attempting to navigate to an attachment, rather it displayed an image of a broken attachment link.

With Trac 1.0, the attachment, th:attachment/wiki/BookmarkPlugin/bookmarkpage.jpg

is now stored at,

$TRACENV/files/attachments/wiki/819/819ffdd855b12bca022d5a9f4e1b75ea2f91b067/4baf82047b92bfcc6bde2217dfc158ead669a4c2.jpg

So I started poking around at the Apache configuration, and seem to have it working with the following change:

  • trac-hacks-010

    old new  
    2727Alias  /chrome/common  /path/to/www/htdocs/common
    2828Alias  /chrome/site    /path/to/www/htdocs/site
    2929Alias  /errorpages     /path/to/www/errorpages
    30 Alias  /raw-attachment /path/to/trac/attachments/
     30# Alias        /raw-attachment /path/to/trac/files/attachments/
    3131
    3232# use mod_rewrite to let Apache handle 0.10-style requests for
    3333# raw attachments
    3434RewriteEngine  On
    3535RewriteCond    %{QUERY_STRING} ^format=raw$
    36 RewriteRule    ^/attachment/(.*) /path/to/trac/attachments/$1 [L]
     36RewriteRule    ^/attachment/(.*) /path/to/trac/files/attachments/$1 [L]
    3737
    3838<Directory     /path/to/www/htdocs>
    3939       Options         -Indexes
    4040       Order           allow,deny
    4141       Allow           from all
    4242</Directory>
    43 <Directory     /path/to/trac/attachments>
     43<Directory     /path/to/trac/files/attachments>
    4444       Options         -Indexes
    4545       Order           allow,deny
    4646       Allow           from all

This is a side-effect of the new storage scheme for attachments, and due to the cryptic naming, mapping them through apache is no longer an option. As far as I can tell there is no way we can keep any of the config rules that point to attachments on disk, and these should be removed.

I complained about this some time ago: trac:comment:25:ticket:10313

But since that time another good solution has been implemented instead: trac:#7894

So install & enable mod_xsendfile seems to be the proper fix for this for Trac 1.0+.

Attachments (0)

Change History (3)

comment:1 Changed 9 years ago by Ryan J Ollos

Description: modified (diff)

comment:2 Changed 9 years ago by Ryan J Ollos

Cc: osimons Steffen Hoffmann Michael Renzmann Jun Omae added
Resolution: fixed
Status: newclosed

Debian 7 has mod-sendfile 0.9, so the following configuration is used:

XSendFile on
XSendFileAllowAbove On

We could use some brief Trac documentation on configuring mod_xsendfile. I'll add that soon.

comment:3 Changed 9 years ago by Ryan J Ollos

Debian 8 has mod-sendfile 0.12 and Apache 2.4., so the following configuration is used:

XSendFile on
XSendFilePath /path/to/trac/env/files/attachments

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.