• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

nginx XSendfile for handling attachments

D.O.A.

Well-known member
#1
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
#3
Hmmm I threw this into my site and since I'm mostly using attachment thumbnails, I'm not noticing an improvement.
 
#6
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.