# X-Accel-Redirect without internal

**URL:** <https://www.ruby-forum.com/t/x-accel-redirect-without-internal/235769>\
**Category:** NGINX\
**Created:** [July 14, 2013, 2:31pm UTC](https://www.ruby-forum.com/t/x-accel-redirect-without-internal/235769 "2013-07-14T14:31:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [July 14, 2013, 2:31pm UTC](https://www.ruby-forum.com/t/x-accel-redirect-without-internal/235769/1 "2013-07-14T14:31:14Z")

</div>

Hello,

My problem is very simple, I’d like to change from php readfile to  
x-accel-redirect. I know exactly how to do it, but I have a problem:

My files are organized like that:  
/home/ID(id of directory on mysql)/ .mp3 .xml and .zip/.rar

I would like to serve the .zip or .rar files by php, but .xml and .mp3  
needs  
to be allowed from accessing directly. When I put /home/ID as internal,  
isn’t possible access the .xml or .mp3 files.

What I need to do to have the xml and mp3 files being accessed directly  
and  
zip/rar by x-accel-redirect ON THE SAME directory?

Any help is appreciated, thanks!

Posted at Nginx Forum:

> **[X-Accel-Redirect without internal](https://forum.nginx.org/read.php?2,240827,240827#msg-240827)**
>
> Hello, My problem is very simple, I'd like to change from php readfile to x-accel-redirect. I know exactly how to do it, but I have a problem: My files are organized like that: /home/ID(id of directory on mysql)/ .mp3 .xml and .zip/.rar I would lik

---

<div class="post-metadata">

**Author:** ![jordanmoreira57](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/858c86/32.png) [@jordanmoreira57](https://www.ruby-forum.com/u/jordanmoreira57)\
**Post date:** [July 14, 2013, 8:42pm UTC](https://www.ruby-forum.com/t/x-accel-redirect-without-internal/235769/2 "2013-07-14T20:42:07Z")

</div>

Hello!

On Sun, Jul 14, 2013 at 08:30:38AM -0400, jordanmoreira57 wrote:

> isn’t possible access the .xml or .mp3 files.
> 
> What I need to do to have the xml and mp3 files being accessed directly and  
> zip/rar by x-accel-redirect ON THE SAME directory?

Try something like this:

location /directory/ {

```
location ~ \.(xml|mp3)$ {
    # accessible
}

location ~ \.(zip|rar)$ {
    internal;
}

```

}

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![jordanmoreira57](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/858c86/32.png) [@jordanmoreira57](https://www.ruby-forum.com/u/jordanmoreira57)\
**Post date:** [July 15, 2013, 12:15am UTC](https://www.ruby-forum.com/t/x-accel-redirect-without-internal/235769/3 "2013-07-15T00:15:20Z")

</div>

Everything appears to be as you asked for. Did you perhaps forget your  
“Content-Disposition” header?

## Jonathan

Jonathan M.  
Oxford, London, UK

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**

---

<div class="post-metadata">

**Author:** ![jordanmoreira57](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/858c86/32.png) [@jordanmoreira57](https://www.ruby-forum.com/u/jordanmoreira57)\
**Post date:** [July 14, 2013, 10:08pm UTC](https://www.ruby-forum.com/t/x-accel-redirect-without-internal/235769/4 "2013-07-14T22:08:35Z")

</div>

I tried something like that:

default.conf:  
location / {  
root /home/;  
index index.html index.htm index.php;

```
    location ~ \.(zip|rar)$ {
      internal;
    }

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

```

teste.php:

\<?php header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-type: application/octet-stream"); header('X-Accel-Redirect: /799/WESLEY SAFADAO BANDA GAROTA SAFADA NO FORRICO EM ICOCE 13072013 by WWWANDRECDCOM.zip'); ?\>

Apparently the file was acessed but the download don’t started, see what  
was  
shown on browser:  
"PK ÊzîBLWESLEY SAFADAO & BANDA GAROTA SAFADA 2013 - FORRICO 2013 by  
[WWW.ANDRECD.COM/UXSàâQ](http://WWW.ANDRECD.COM/UXS%C3%A0%C3%A2Q)\ìâQõPK{îB›WESLEY SAFADAO & BANDA GAROTA  
SAFADA 2013 - FORRICO 2013 by [WWW.ANDRECD.COM/01](http://WWW.ANDRECD.COM/01) - [WWW.ANDRECD.COM](http://WWW.ANDRECD.COM) -  
Wesley  
Safadao & Banda Garota Safada no Forrico  
2013.mp3UXÉìâQÉìâQõì¹eTœM·-ÚxÐàî4îÜÝÝi—F ¸»5Ü÷àî î4@  
9¼ßþÎÞwœ{þí;î½cœÌ5ž¹ªV¯YOUý˜Õ­ Í´ d4ÿa/‹ƒ“ --¡ýï˜ƒŸ“  
­,£úÂ\_ý3.È-ÈËÐ–Q•z‰¨\_š–‹§³5¥¬‹;È†RÝÝ…’“ƒ‹ƒ’QÒìhMÉÉPWÀyœ½ä‚,@6ìö®6  
—àÏòŸïlEYYÀúåø³…½/ã¶TTÌÿÒD„À¿0Ô—@1@|áp/;;çŸ’À?& ¼ôa¼Äb/  
@vüïùþÅ\_üÅ\_üÅ\_üÅÿ‘ð;;yz€­^(R\<Â¿¼þ‹g(ˆGüOÞ”˜ð/ŽÀÃ$&þÿ/_ñ\*õŸZ}Å\_üÅ\_üÅ\_üÅÿÙøç§!N!NAÊÂ+  
Ä!ð¿í{q 0Ààðx¼°ŒÈŸ-tR;ÄUˆÝÙƒÍÂÚÅÒ†ÍÊÅ‰ÝÇÂ•“ƒ  
"îãjaå`¡´´E.Ú»(ÁÖ¢z¼**®R6v`y?w-?Um+?+Akq1L4!'W’ˆ¥“£³‡(õ¿ª½ðºÙ©ÅDÜ­m…4¥eÿñ‰Rÿ{.ÞÞÞlÞÜl.î  
vNAAAv.v…àKÐÃ×bátö ùwi+w°+ìâLùOlaéâ ¥öô[ÙZØòZZ[ó–¸­œœÖ@knN  
57·5?/§—-§%õ¿å­­þSÝÕÓÝñ\_ÚÖVì6Ž6N6Î—Õàd§fÿVóe‰þSô»ü/ïø’#$ånc±‘~ibÿl,ƒÈ)¨ý?7–‡‡_„ýÉaÿ\_&úÿÁj‰‰X[  
Yý3’÷ÿ×²qûïí¶#XìÚèÿxÃ—Žÿ  
/¥\_Î\*\*ªûÿUõÿ¾ìÿ\>v/ì?éË7)ÿ\_À\_‘¿"EþŠüù+òWäÿ\_"ÿetmœ\_Ü­÷‹ý³úç/Áÿþ)òß­÷§€ó  
pG €ÇCÀûÓ ààQààþë\*€„ˆ€G@y…Š‡þ’  
ýÁààáQ‘ÑÐáà‘Qppñ^áP  
¨Ð©9i$ˆh5,Þ“Ðqéº%ÌÐ3h&Cçxø¤´u,mƒ“R{gùÃæ%eÝ—^J’ÿ3ªþ—_Ü‹""ò+$Ô—aMœBd$$$dtd”—Q_§\<¢†…rn´î  
uïÌ+|É­K.Ë`“M÷\>TÂ746¶É)õ³óÄ\<üRÒ©rÚz^a”

Just stranger characters.

Posted at Nginx Forum:

> **[Re: X-Accel-Redirect without internal](https://forum.nginx.org/read.php?2,240827,240835#msg-240835)**
>
> Hello, My problem is very simple, I'd like to change from php readfile to x-accel-redirect. I know exactly how to do it, but I have a problem: My files are organized like that: /home/ID(id of directory on mysql)/ .mp3 .xml and .zip/.rar I would lik
