nginx XSendfile for handling attachments

D.O.A.

Well-known member
We've got a lot (50,000+) of attachments on our forum and Xsendfile/X-accel was recommended. Can any proficient nginx users here verify the below is working as intended? We're trying to optimize attachment handling without breaking view counters or removing permissions.

http://wiki.nginx.org/X-accel
I have tested this in /XenForo/ViewPublic/Attachment/View.php

PHP:
return new XenForo_FileOutput($this->_params['attachmentFile']);
withoutx.JPG

replaced with

PHP:
$this->_response->setHeader('X-Accel-Redirect', str_replace(XenForo_Application::getInstance()->getRootDir(),'', $this->_params['attachmentFile']));
return '';
withx.JPG

So in theory nginx is doing all the work now?
I'm wondering would this also require a defined internal location aka into /internal_data folder etc on the nginx config side.
 

silence

Well-known member
Hmmm I threw this into my site and since I'm mostly using attachment thumbnails, I'm not noticing an improvement.
 

D.O.A.

Well-known member
Configure your server stanza to support it also, it's taking the load of php for me
 

silence

Well-known member
Configure your server stanza to support it also, it's taking the load of php for me
What do you mean 'server stanza'?
Would you be so generous as to post any snippits that could be of use to other users?
 

HittingSmoke

Active member
We've got a lot (50,000+) of attachments on our forum and Xsendfile/X-accel was recommended. Can any proficient nginx users here verify the below is working as intended? We're trying to optimize attachment handling without breaking view counters or removing permissions.

http://wiki.nginx.org/X-accel
I have tested this in /XenForo/ViewPublic/Attachment/View.php

PHP:
return new XenForo_FileOutput($this->_params['attachmentFile']);
View attachment 42492

replaced with

PHP:
$this->_response->setHeader('X-Accel-Redirect', str_replace(XenForo_Application::getInstance()->getRootDir(),'', $this->_params['attachmentFile']));
return '';
View attachment 42493

So in theory nginx is doing all the work now?
I'm wondering would this also require a defined internal location aka into /internal_data folder etc on the nginx config side.
I'm very interested in seeing how this turns out. Attachment optimization is something that's been bugging me. I don't want to lose the ability to apply permissions to attachments but serving them from PHP is never ideal.
 
Top