#11981 closed enhancement (fixed)
Add support for the nginx X-Accel-Redirect header
Reported by: | Owned by: | Jun Omae | |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.6 |
Component: | web frontend | Version: | |
Severity: | normal | Keywords: | nginx |
Cc: | Branch: | ||
Release Notes: |
Add |
||
API Changes: | |||
Internal Changes: |
Description
Hi,
I am using X-Accel-Redirect with Trac in FastCGI mode by changing header name in the api.py. I am recommending to make this header name configurable or to add use_x_accel_redirect variable in the config. I can provide patch for this change. On the nginx side appropriate location looks like that:
# serve attachments by nginx directly location /data/trac/files/attachments/ { internal; alias /data/trac/files/attachments/; }
Attachments (2)
Change History (22)
follow-up: 6 comment:1 by , 10 years ago
Milestone: | → unscheduled |
---|
by , 10 years ago
Attachment: | use_xaccelredirect.patch added |
---|
patch to send X-Accel-Redirect for nginx
comment:2 by , 10 years ago
I added patch to support X-Accel-Redirect on trunk. Please let me know if you need anything else, thank you.
comment:3 by , 10 years ago
Patch tested with Trac 1.0.4 with nginx/1.6.2 and seems to work correctly. It would be great to see it in the 1.0.5 to avoid local patches on upgrade :)
comment:4 by , 10 years ago
Milestone: | unscheduled → 1.0.6 |
---|
comment:5 by , 10 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
Thanks for the patch. However, it doesn't seem that works well, e.g. missing to add use_xaccelredirect
to Request.callbacks
like tags/trac-1.0.5/trac/web/main.py#L169. I'll post revised patch.
comment:6 by , 10 years ago
Keywords: | nginx added |
---|
Replying to jomae:
X-Sendfile
header via apache with mod_xsendfile has been implemented in #7894.
Also, previous discussion about X-Accel-Redirect
in comment:10:ticket:7894.
comment:7 by , 10 years ago
Seems like the getattr
in [11071#file0] shouldn't really be needed since the attribute is set in the callbacks
.
comment:8 by , 10 years ago
Proposed changes in jomae.git@t11981, adding [trac] xsendfile_header
option which specifies the header to use if X-Sendfile
feature is enabled. If Nginx is used, set X-Accel-Redirect
to the option.
comment:9 by , 10 years ago
The changes look good to me. It might be a good idea to mention the value to use with Nginx in the option comment.
comment:10 by , 10 years ago
Thanks for the reviewing. Added mention to the option's document in [69f003e3c/jomae.git].
I'll push it later.
comment:11 by , 10 years ago
Thanks! I will test proposed patch today and will tell if it works correctly.
comment:12 by , 10 years ago
I am getting 500 error with text
Trac detected an internal error: AssertionError: Header names must be strings
I used
use_xsendfile = true xsendfile_header = X-Accel-Redirect
comment:13 by , 10 years ago
This is traceback:
Python Traceback Most recent call last: File "/usr/lib/python2.6/site-packages/trac/web/main.py", line 520, in _dispatch_request File "/usr/lib/python2.6/site-packages/trac/web/main.py", line 226, in dispatch File "/usr/lib/python2.6/site-packages/trac/attachment.py", line 531, in process_request File "/usr/lib/python2.6/site-packages/trac/attachment.py", line 886, in _render_view File "/usr/lib/python2.6/site-packages/trac/web/api.py", line 628, in send_file File "/usr/lib/python2.6/site-packages/trac/web/api.py", line 462, in end_headers File "/usr/lib/python2.6/site-packages/trac/web/_fcgi.py", line 1250, in start_response
comment:14 by , 10 years ago
also local variables
exc_info None headers_sent [] headers_set [] name u'X-Accel-Redirect' response_headers [('ETag', 'W/"samm2/Sun, 27 Sep 2009 10:49:41 GMT/True"'), ... status '200 Ok'
comment:15 by , 10 years ago
I been able to fix this by replacing line
xsendfile_header = getattr(self, 'xsendfile_header', None)
with
xsendfile_header = getattr(self, 'xsendfile_header', None).encode("ascii")
comment:16 by , 10 years ago
The following patch may be a simple fix, though I'm not surprised comment:15 would also work:
-
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py index 7fe256b..8fc131a 100644
a b class RequestDispatcher(Component): 335 335 return self.use_xsendfile 336 336 337 337 def _get_xsendfile_header(self, req): 338 return s elf.xsendfile_header338 return str(self.xsendfile_header) 339 339 340 340 def _pre_process_request(self, req, chosen_handler): 341 341 for filter_ in self.filters:
comment:18 by , 10 years ago
Sorry, I've tested with only tracd
. Updated jomae.git@t11981. In [a2bd1cb9/jomae.git], converts to str
using to_utf8()
and validates to use only valid characters in the option.
comment:19 by , 10 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
X-Sendfile
header via apache with mod_xsendfile has been implemented in #7894.PatchWelcome.